-1

I'm trying to program a Two Body Problem in SDL 1.2 So in that program I would have two bodies right, my question is what data would I need for each Body? The program is just the two bodies rotating around in a certain orbit. I would create a class for each Body, and store the data in there. I believe I would need the following data mass1, mass2 (mass for each body) speed1, speed2 (initial speed for each object) angle1, angle2 (angle in which direction the object will travel at the start of the simulation) distance (the distance of the objects from each other)

I'm not sure if I'm right or not, would I need any other data for the objects, or is some of the date I said a bit off?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • This is a bit open-ended this and not a great question. But, ask yourself how you'd work out the position of the bodies using pen and paper. – Skizz Jan 06 '14 at 16:42
  • There's probably a number of different ways to do it, but I would start with each object having a mass, a vector indicating position, and a vector for velocity (which incorporates both speed and direction). You could store things like angle, etc., but, since the same information can be derived simply from the velocity vector, it would be redundant - although in certain situations it might be useful as a "cached value", so you don't have to recalculate it repeatedly... – twalberg Jan 06 '14 at 17:08

1 Answers1

1

Since your problem is in 3-space, you would need 6 positional parameters for each body, and mass. How exactly you code those parameters is up to you. If you want to give the coordinates in Cartesian coordinates, store the x, y and z components of the position and the x, y and z components of the velocity. If you want to use polar coordinates, you will need a magnitude, an azimuth angle and an elevation angle. The configuration you mentioned so far has a mass, speed, velocity azimuth and velocity elevation. You also need to include the initial positions. I would recommend switching to Cartesian coordinates throughout since the integration will look more uniform across the different directions.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • I'd also recommend keeping the total system energy, momentum and angular momentum. They're conserved quantities. Storing them means the set of variables is overdimensioned, but you need to address accumulation of rounding errors. It may also be useful to store the center of gravity (in addition to momentum) and do all calculations relative to the CoG. – MSalters Jan 08 '14 at 09:31