I'm helping some middle-school students write a spacecraft simulator. As part of that, I'm trying to wrap my head around orbital mechanics today, mainly using this excellent guide: http://www.braeunig.us/space/orbmech.htm
But of the six orbital elements it says are required, there's one I don't understand: argument of periapsis. This is defined as the angle between the ascending node and the periapsis point. But how could this angle ever be anything other than 90°? I'm having real trouble picturing that.
More to the point, I guess, is: what do I do with this parameter to actually calculate a position (in 3D space) on an orbit? Currently I'm doing this:
public Vector3 PointAtAngle(float radians) {
float r = RadiusAtAngle(radians);
// Start by finding the orbital point in the XZ plane
// (i.e., the plane against which the inclination is measured),
// around a focus of zero, and aligned on the X axis.
Vector3 p = new Vector3(r * Mathf.Cos(radians), 0, r * Mathf.Sin(radians));
// Then rotate this by the inclination around the Z axis.
p.Set(p.x * Mathf.Cos(i), p.x * Mathf.Sin(i), p.z);
// Rotate around the Y axis according to the longitude of ascending node.
float cosYRot = Mathf.Cos(omega);
float sinYRot = Mathf.Sin(omega);
p.Set(p.x * cosYRot - p.z * sinYRot, p.y, p.x * sinYRot + p.z * cosYRot);
// Finally, add the focus to shift to whatever we're orbiting around.
return focus + p;
}
Here, RadiusAtAngle just computes the distance from the focus point from the angle, semimajor axis (a), and eccentricity (e). I'm pretty confident in that. Then I do a bit of trig to find a point around the origin in the XZ (ecliptic) plane, rotate this up (around the Z axis) by the inclination (i), and rotate it around the Y axis by the longitude of the ascending node (omega). And finally, add in the focus point.
This all appears to work great, and by tweaking a, e, i, and omega, I can make any-shaped orbit I can imagine. But this is probably a failure of imagination on my part. How does this argument of periapsis come into it?