How to calculate time until node?

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
697
Reaction score
264
Points
78
Location
This place called "home".
Yeah, as the title says, I want to know how long time there is until I pass a node.

The result will be used to show the time until a spacecraft passes the equator in a MFD, so I can know all the parameters that Orbiter gives me.
I can myself find a value which goes down to zero when I pass the equator, but it doesn't count in a linear fashion.
For that method, I use the following code
PHP:
AngleOfPerigee = LongitudOfPeriapsis - LongitudeOfAscendingNode;

AngleOfNode = AngleOfPerigee + TrueAnomaly;

AngleUntilNode = pi - AngleOfNode;

TimeUntilNode = OrbitalPeriod * AngleUntilNode / 2pi;

But as the rate of change for TrueAnomaly changes (dTrA/dt is not constant for non-circular orbit), the calculated time to node will not show the true time to passage, but will speed up counting when moving fast and slow down the counting when moving slow.

I guess the solution would be to solve some differential equation, but what equation? I have searched the Internet for answers, but found nothing, so now I turn to you.
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
I have searched the Internet for answers, but found nothing, so now I turn to you.

Why not simply use StoreStatus() and RecallStatus(), instead of being dependent on third party libraries?

Now think about it:
Wouldn't it be nicer, if you found on the Internet a library that calculates it for you, so that you don't need to solve differential equations? It turns out that there is one that does it!
https://sourceforge.net/p/enjomitchsorbit/codeHG/ci/default/tree/lib/Math/SpaceMath.cpp#l45
and:
https://sourceforge.net/p/enjomitchsorbit/codeHG/ci/default/tree/launchmfd/TGTPARAM_ORB.cpp#l45

Of course, the equator requirement is just a special case of what the code above does. Just define the equator as targetAxis, as in the TGTPARAM_ORG.cpp above.
 

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
697
Reaction score
264
Points
78
Location
This place called "home".
Thank you, but I have trouble understanding your code. From what I can see, in the TGTPARAM_ORB.cpp file, you only consider a circular orbit (line 67), while I need a solution for an elliptic orbit. Am I missing something?


I only assumed that I would need to find the time by iteration. If I can use an algebraic equation, that would naturally be preferred.
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Right. I should have read the description better.
Are you familiar with [ame="http://www.orbithangar.com/searchid.php?ID=3825"]KOST[/ame]? At least thanks to this library, you'll be able to learn the future speed(s) in advance and maybe average it, until you find a better solution.

Sorry, but no algebraic solution from me without sacrificing my family life :)
 
Last edited:

Thorsten

Active member
Joined
Dec 7, 2013
Messages
785
Reaction score
57
Points
43
But as the rate of change for TrueAnomaly changes (dTrA/dt is not constant for non-circular orbit), the calculated time to node will not show the true time to passage, but will speed up counting when moving fast and slow down the counting when moving slow.

Something tells me that's why they invented mean anomaly...

Anyway, if you know true anomaly of two points and eccentricity, you can use this series expansion to get mean anomalies, and the difference in mean anomalies is directly related to a time.

There might be more elegant ways to solve it, this is just my first idea.
 

indy91

Addon Developer
Addon Developer
Joined
Oct 26, 2011
Messages
1,232
Reaction score
635
Points
128
With the "AngleUntilNode" you already have the most important number. If the true anomaly and "angle of perigee" are properly calculated, then it should also be valid for elliptical orbits.

All you need to do is convert the true anomaly of your vessel and the true anomaly of the node to their mean anomalies, with the eccentric anomaly as an intermediate step. In your equations the true anomaly of the node seems to be "pi - AngleOfPerigee". Here the equation to get the eccentric anomaly from the true anomaly:

[MATH]E = 2*\arctan{(\sqrt{\frac{1-e}{1+e}}\tan{\frac{\theta}{2}})}[/MATH]
E = eccentric anomaly
e = eccentricity of the orbit
Theta = true anomaly

You have to do this both with the "TrueAnomaly" and the "pi - AngleOfPerigee" term. When you have the two eccentric anomalies, calculate the mean anomalies:

[MATH]M_e = E - e \sin{E}[/MATH]
M_e = Mean anomaly

If you have the two mean anomalies, you can simply use the difference between them as "AngleUntilNode". Your last equation applies to the mean anomalies of an elliptical orbit just as it applies to the true anomaly difference for a circular orbit.
 

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
697
Reaction score
264
Points
78
Location
This place called "home".
Thank you to all, but I couldn't get any of your methods to work, but I finally solved it myself, with help from this paper.

If anyone finds this thread while searching for the same problem, here is my solution:

PHP:
double APe = el.omegab - el.theta; // Angle of perigee, LPe - LAN
double AngleToNode = fmod(APe + TrA, PI2); // Angle since ascending node, between 0 and PI2
if (AngleToNode < PI)
{
	AngleLeftToNode = PI - AngleToNode; // Angle between us and next node
	sprintf (AorDNode, "(+)"); // Ascending node
}
else
{
	AngleLeftToNode = PI2 - AngleToNode; // Angle between us and next node
	sprintf (AorDNode, "(-)"); // Descending node
}
// Calculation of time to node. Method based on: https://works.bepress.com/eric_addison/1/
double phi = fmod(AngleLeftToNode + TrA, PI2); // Angle between perigee and node
double E2 = Ecc * Ecc; // Ecc squared

double AreaFromMeToNode = pow(SMa * (1.0 - E2), 2.0) * (OrbitArea(phi, Ecc) - OrbitArea(TrA, Ecc)); // Area swiped over by orbit from current position to node
double TimeFromMeToNode = T * AreaFromMeToNode / (PI * SMa * SMa * sqrt(1.0 - E2)); // Time it takes to swipe the area (from Kepler's 2nd equation)
TimeToNode = fmod(TimeFromMeToNode + T, T); // Time to node is between 0 and orbital period T

where the function OrbitArea(angle, eccentricity) returns the number

PHP:
double AreaResult = (Ecc * tan(angle / 2.0) / ((1.0 - Ecc * Ecc) * (Ecc * tan(angle / 2.0) * tan(angle / 2.0) - tan(angle / 2.0) * tan(angle / 2.0) - Ecc - 1.0)) - (-PI * floor(angle / PI2 + 0.5) + atan((Ecc * tan(angle / 2.0) - tan(angle / 2.0)) / sqrt(1.0 - Ecc * Ecc))) / (sqrt(1 - Ecc * Ecc) * (1 - Ecc * Ecc)));

Here is the same function in LaTeX, if you want to see it in a more natural looking form:
[math] A = \frac{e \tan{ \frac{\alpha}{2} } }{ \left(1 - e^2\right) \left(\left(e - 1\right) \tan^2{\frac{\alpha}{2} } - e - 1\right)} - \frac{ \arctan{\left(\frac{(e - 1)\tan{\frac{\alpha}{2}}}{\sqrt{1 - e^2}}\right)} - \pi \times floor \left(\frac{\alpha}{2 \pi} + \frac{1}{2}\right)}{\sqrt{1 - e^2} \left(1 - e^2\right)} [/math], where A is area (well, strictly not until you multiply with SMa^2*(1-ecc^2)^2), alpha is input angle and e is eccentricity

Then the value TimeToNode will give you the remaining time until next node. Please note that this code is only valid for an orbit with eccentricity < 1, as we will get a complex number for sqrt(1 - Ecc^2) if Ecc > 1, and therefore not a valid time.
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
I was afraid it wouldn't be that simple, but OTOH I wouldn't imagine that it it's so complex.
Thanks for sharing.
 
Top