To answer this question, let us compare Figure 7.5 and Figure 8.1. The leaders in Figure 8.1 are nice and evenly spread in space, with an equal number of rockets going up, down, right or left. By contrast, the little blue squares on Figure 7.5 are not evenly spread at all: they are much more tightly arranged near the north and south poles than they are around the equator. Why? Because, in lesson7.wdl, we increased phi by 10 degrees for all values of theta. This gives 360/10 = 36 blue squares in each horizontal circle (= circle of constant theta or latitude). Since the circles of constant latitude are smaller near the poles, the particles need to be squeezed tighter there than near the equator. If we choose the initial velocities of the leaders this way, more will be sent in the up and down directions than in the other directions. It would not look very pretty (though it could create an interesting effect) nor realistic since explosions in mid-air usually send material and debris in every direction with equal probability. It is gravity which pulls all of them toward the ground afterwards.
To fix this, we increment phi using a variable dphi which takes a larger value near the poles (i.e. theta near 0 or 180) than near the equator (i.e. theta close to 90). This way, we fire fewer leaders in the former directions than in the latter.
First, for the theta angle. We have:
nb_theta = pi/spacing; dtheta = 180/nb_theta;
with nb_theta equal to the number of divisions of the sphere in the vertical (or theta) direction. This can be adjusted by choosing values for variable spacing: if spacing is large, we get fewer divisions; if it is small, we get more.
For phi, we have variables
nb_phi = 2*pi*sin(theta)/spacing; if (nb_phi!=0) { dphi = 360/nb_phi; } else { dphi = 360; }
nb_phi is the number of divisions of the sphere in the horizontal (phi) direction. It depends on spacing, and on theta as well because of the factor sin(theta). If theta = 0 (at the north pole) or 180 (at the south pole), nb_phi = 0. The if statement below it then sets dphi = 360 degrees, which gives just one value of phi in the loop in a_chrysanthemum: only one leader is fired.
If theta = 90 degrees (at the equator), sin(theta) = 1 and nb_phi = 2*pi/spacing. This gives a small value for dphi, and consequently the loop produces a large number of values for phi: lots of leaders will be created.
For theta between 0 and 180, we get intermediate values for nb_phi, dphi and the number of leaders fired. The overall result is the nice, spherically symmetric distribution of leaders shown on Figure 8.1.
One might think "It looks nice, but how did you come up with the expressions for dtheta and dphi. Is it hard?"
Not at all. Here is how it's done. dtheta (dphi) is just equal to the total range of angle theta (phi), which is equal to 180 (360) degrees, divided by nb_theta (nb_phi). To see how we can compute nb_theta and nb_phi, check out Figure 8.2.
Figure 8.2: (left) The length of the half-circle going from the north pole to the south pole of a sphere of radius r is equal to (1/2)*2*pi*r = pi*r. (right) The length of a full circle with theta constant is equal to 2*pi *r*sin(theta) since r*sin(theta) is the radius of that circle (see Figure 7.2-middle and lesson 7.a).
It illustrates that the length of the half-circle linking the poles of an arbitrary sphere of radius r is equal to pi*r. Similarly, the length of a horizontal circle of constant latitude angle theta is equal to 2*pi*r*sin(theta). Let spacing be some distance. We find how many times we can fit spacing in the vertical half-circle and the horizontal circle, by dividing their respective lengths by spacing. We then obtain nb_theta and nb_phi, respectively:
nb_theta = pi*r/spacing nb_phi = 2*pi*r*sin(theta)/spacing.
But what about the radius r? Actually, since we did all this reasoning for a sphere of arbitrary radius, we can just drop r in the equations above. You can think of it as if we absorbed r in spacing: just choose the value of spacing which fits your needs. That is it. :-) What is really important here is the theta dependence of nb_phi.
Next: 8.c Slowing down the leaders and shifting the color of the tail