To conclude the Semester of Supercomp, we had to make some kind of computer simulation of something. I chose projectiles. Now, you may be thinking, Gee, Gary, projectiles are pretty easy. We learned about them all the way at the beginning of our physics book! True enough, it's infact quite easy to set up the quadratic equation and solve that to find whether or not a projectile fired with a given initial velocity and initial angle with the horizontal will, in fact, hit a target. But what if you throw another factor in?
Hmm, you say, that's a good idea. How about you make the target really massive, so its gravity affects the path of the projectile?
So I tried that. Unfortunately, I had to toss that idea. The gravity had no significant (i.e., noticeable) effect on the projectile until I raised the target's mass to about 5E14 kilograms. At that point (when I was only drawing a single path at a time), I noticed that OpenGL would not draw the entire path; the projectile's velocity had become so great because of the gravitational pull that it had gone off the screen because it was in excess of about 300,000c, which causes some relativity problems, not to mention the target's gravity affecting the entire Earth. So I scrapped that.
So what else did you try?
Well, I factored in something else that (a) doesn't cause problems with relativity, and (b) makes the path become significantly more difficulty than a quadratic equation.
What did you add, a bunch of physical obstacles?
Well, no, not unless you count air as an obstacle.
Ohhh... I see, since the deceleration due to air resistance is proportional to the square of velocity, you turned a quadratic equation into an overly complicated differential equation!
Correct. I included air resistance in the simulation. The forces now acting on the projectile are the Earth's gravitational pull and air resistance. Suppose that we have the usual orthonormal basis for the Cartesian coordinate system, the mass of the projectile is m, and that the current velocity is v at an angle T (sorry, HTML doesn't provide well for Greek letters). The combined forces on the object, in Newtons, are <0, -mg> + (1/2)CdpAv2<cos T, sin T>. In this equation, g is the usual 9.81 m/s2, Cd is the coefficient of drag, which is about 0.5 for a spherical object like the projectile, p (which should be a rho) is the density of air (about 1.225), and A is the cross-sectional area of the projectile perpendicular to its motion, which is always just pi r2 for a sphere.
First, for the purposes of validation (verifying the results given by the simulation), I wrote a program (Projectile Fun, Part I) which draws the trajectory of the object both with and without air resistance. Then I did Part II, which does not draw the individual paths but plots all the possible trajectories within a given range by coloring a graph based on where the projectile lands.
I calculated only the points necessary to fill in a graph. The program
(Part II) plots a standard Cartesian plane in a 480x240 window, and although
there is some of each quartile in the graph, everything other than I is just
there to create some space. I calculate one value per pixel in the ranges
v0
[0, 2000 m/s] and
theta0
[0, pi/2]. It then plots
it based on color: if it misses the target (which has a radius of 20 m)
then it is a shade of gray (the lighter it is, the closer the projectile
came), and if it hits it plots a shade of green (again, lighter = closer).
Slightly out beyond the range of values that hit the target, though, the
graph is for some reason all green.
I first let the program do all the heavy work itself, calculating and storing all needed values for the graph in an enormous matrix of doubles. Then, I tried to use PVM to have slave programs calculate an entire column (column based on the graph; that is, I give it v0 and it works over the whole range of initial angles) of values at once, but after sending and receiving about 32 columns normally it would send out the next batch of 16 and just stop receiving. I did not manage to fix this error.
See for yourself! The thumbnails are below; click on either to get the full-size images. It's a bit difficult to see the thin green line on the second image, where the projectiles actually hits the mark, but you can barely see it right in the center of the bright white curves. It's much more clearly visible in the full image.