General Question Calculating Longitude of Ascending Node in Orbiter

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I wasn't sure I should put this under "Math and Physics or "SDK" but I'm trying to write a class/function that will generate Keplerian elements (in the reference body's equatorial frame) from the outputs of "oapiGetRelativePos()" and "oapiGetRelativeVel()".

However I'm having issues calculating the longitude of my ascending node. In theory the angle between my node vector and the planet's horizontal reference axes (x and z in Orbiter) should give me my orbit's longitude but this is not the case. The value returned by theta does not match LaN as reported by Orbiter.

Either the scenario editor is using a different "equatorial frame" or I am doing something wrong.

Code:
void Orbit::UpdateStateVectors(VECTOR3 rvel, VECTOR3 rpos)
{
	// Reference axes of central body 
	MATRIX3 pRot = identity();
	oapiGetRotationMatrix(rbody, &pRot);
	VECTOR3 p_x = { pRot.m11, pRot.m21, pRot.m33 };
	VECTOR3 p_y = { pRot.m12, pRot.m22, pRot.m32 };
	VECTOR3 p_z = { pRot.m13, pRot.m23, pRot.m33 };

	// Angular momentum vector (orbit normal)
	vH = crossp(rvel, rpos); 

	// Inclination
	if (length(vH) > 0.0) inc = acos(dotp(p_y, unit(vH))); // angle between equitorial and orbital planes
	else inc = 0.0;

	// Line of nodes
	vA = -crossp(p_y, vH);
	if (length(vA) > 0.0) normalise(vA); 
	else vA = p_x;	

[I]	// Longitude of ascending node
	double n1 = dotp(p_x, vA);
	double n2 = dotp(p_z, vA);
	theta = atan2(n1, n2); [/I]

	// Eccentricity vector...

Note: "rbody" in this case is the central body of the orbit. "rpos" and "rvel" are the satellite's position and velocity relative to the central body.
 
Top