HarvesteR
Member
- Joined
- Apr 22, 2008
- Messages
- 386
- Reaction score
- 15
- Points
- 18
Hi again,
I'm studying math again :thumbup:
Spent last light reading through Wikipedia, and got reminded of how much I hate math notation
Anyways, what I'm trying to figure out is how to plot an orbital ellipse from initial state vectors...
The trouble I'm having is with some parameters which, for simplicity, I've ignored in my simulation...
For instance, the force of gravity in my sim is a constant -9.81m/s/s, and the primary body (the planet) is completely stationary... Which means the planet has no specified mass...
since I'm applying 1g of force as gravity, I assumed it was safe to use Earth's standard gravitational constant... but I'm not too sure about that...
also, my engine uses Y-up coordinates, so I also assumed it was correct to swap out Z and Y from the original formulae from wikipedia, since it says all it's vectors are in Z-up notation...
Here's what code I have until now... all variables are commented as to what they are (or should be)... the initial state vectors are taken from the static FlightState class that contains the current state of the ship, relative to the center of the planet.
Hopefully you guys can make sense of this... it's probably noobishly wrong... (hence this post)
note that it's also unfinished... I couldn't make sense of the formulae for all the parameters, since my simulation is missing a few, so I'm unsure what to use...
what I intend to get out of this is a full transform to apply to a deformable ellipse... but I'm starting out just by trying to calculate all the needed parameters... later I'll deal with the engine specifics
Many thanks in advance for any help
Cheers
I'm studying math again :thumbup:
Spent last light reading through Wikipedia, and got reminded of how much I hate math notation
Anyways, what I'm trying to figure out is how to plot an orbital ellipse from initial state vectors...
The trouble I'm having is with some parameters which, for simplicity, I've ignored in my simulation...
For instance, the force of gravity in my sim is a constant -9.81m/s/s, and the primary body (the planet) is completely stationary... Which means the planet has no specified mass...
since I'm applying 1g of force as gravity, I assumed it was safe to use Earth's standard gravitational constant... but I'm not too sure about that...
also, my engine uses Y-up coordinates, so I also assumed it was correct to swap out Z and Y from the original formulae from wikipedia, since it says all it's vectors are in Z-up notation...
Here's what code I have until now... all variables are commented as to what they are (or should be)... the initial state vectors are taken from the static FlightState class that contains the current state of the ship, relative to the center of the planet.
Code:
float inc; //inclination
float ecc; //eccentricity
float lan; //longitude of ascending node
float aPe; //argument of periapsis
float meA; //mean anomaly
float orP; //orbital period
float sma; //semi-major axis
float soe; //specific orbital energy
Vector3 ram; //specific relative angular momentum vector
float u = 398600.441f; // standard gravitational constant for earth
float G = 6.6725985e-11f; // Big G constant
void Update()
{
// let's go
// I'm assuming that all calculations from Wikipedia are Z-up, so I'm swapping out Z and Y wherever they're present
Vector3 pos = FlightState.position;
Vector3 vel = FlightState.velocity;
ram = Vector3.Cross(pos, vel);
inc = Mathf.Acos(ram.y / ram.magnitude); //swapped z for y here
Vector3 eccV = (Mathf.Pow(vel.magnitude, 2f) * pos) / u - (pos / pos.magnitude); //points towards periapsis
ecc = eccV.magnitude;
Vector3 lanV = Vector3.Cross(Vector3.up, ram); //lanV points towards the ascending node
lan = lanV.z >= 0f ? Mathf.Acos(lanV.x / lanV.magnitude) : 2f * Mathf.PI - Mathf.Acos(lanV.x / lanV.magnitude);
aPe = Mathf.Acos(Vector3.Dot(lanV, eccV) / (lanV.magnitude * eccV.magnitude));
}
Hopefully you guys can make sense of this... it's probably noobishly wrong... (hence this post)
note that it's also unfinished... I couldn't make sense of the formulae for all the parameters, since my simulation is missing a few, so I'm unsure what to use...
what I intend to get out of this is a full transform to apply to a deformable ellipse... but I'm starting out just by trying to calculate all the needed parameters... later I'll deal with the engine specifics
Many thanks in advance for any help
Cheers
Last edited: