calculating transfer radius over time

Bud

Tutorial Publisher
Tutorial Publisher
Joined
Nov 17, 2008
Messages
8
Reaction score
0
Points
0
Hi all.

I'm thinking of writing a program to simulate going from lunar orbit to the surface by providing the program with an initial orbital radius (it will then assume a perfect orbit) and looping through the code until the craft hits the surface. The initial set up of the orbit is easy enough but I'm stuck working out how to track the change in the transfer radius over time. I think once I can calculate the radius everything else will follow. Any thoughts?

Andy
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
As I understand it, you have a craft in a circular orbit around the Moon; it executes a retrograde burn at some time that lowers orbital periapsis below the lunar surface; and you want to track the orbital radius of the craft (its height above the surface) as a function of time?
 
Last edited:

Bud

Tutorial Publisher
Tutorial Publisher
Joined
Nov 17, 2008
Messages
8
Reaction score
0
Points
0
As I understand it, you have a craft in a circular orbit around the Moon; it executes a retrograde burn at some time that lowers orbital periapsis below the lunar surface; and you want to track the orbital radius of the craft (its height above the surface) as a function of time?

That's how I was thinking of doing it. From the radius I think I can calculate all other orbital elements that I would want the sim to display.
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
Basically, you need to solve the following equation for [MATH]r[/MATH]:

[MATH]\Delta \tau =\sqrt{\frac{\left(r_a+r_p\right){}^3}{8 \mu }} \left(\pi -2 \left(\tan ^{-1}\left(\sqrt{\frac{r-r_p}{r_a-r}}\right)-\frac{\sqrt{\left(r_a-r\right) \left(r-r_p\right)}}{r_a+r_p}\right)\right)[/MATH]
where [MATH]r_a[/MATH] is the radius of the radius of the initial circular orbit; [MATH]r_p[/MATH] is the periapsis radius; [MATH]r[/MATH] is the radius of the transfer orbit (i.e., the thing you are solving for); [MATH]\mu=4.90487\times 10^{12}[/MATH] is the standard gravitational parameter for the Moon (in SI units); and [MATH]\Delta t[/MATH] is the time interval after the periapsis lowering burn. To solve this equation for [MATH]r[/MATH], you need to use some general (and robust) root-finding algorithm - such as Brent's Method.

As a numerical example. Suppose that the initial orbital altitude is [MATH]20\,km[/MATH]; and that periapsis is lowered to an altitude of [MATH]-20\, km[/MATH]. What is the orbital altitude 100 seconds after the periapsis lowering burn? Here, [MATH]r_a=1758100\,m[/MATH]; [MATH]r_p=1718100\,m[/MATH]; and [MATH]\Delta t=100\,s[/MATH]. Then, solving the above equation, we get [MATH]r=1758008.76\,m[/MATH], or an altitude of [MATH]19.908\, km[/MATH]
Does that answer your question?
 
Last edited:

Bud

Tutorial Publisher
Tutorial Publisher
Joined
Nov 17, 2008
Messages
8
Reaction score
0
Points
0
Thanks, there's a fair bit of reading up for me to do understand that but I'll give it a go!
 

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?
Have a look at my blog post here, if you're looking for a solver. "Root finding" is the relevant topic. You got yer Bisection and Brent algorithms exposed through a nice interface.
 

Bud

Tutorial Publisher
Tutorial Publisher
Joined
Nov 17, 2008
Messages
8
Reaction score
0
Points
0
Is there anychance you could work through an example from the equation to help me understand it, this is a bit beyond my maths skills (or lack of)!
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
Solving the equation for 'r' as a function of 'time' is tricky because one really does need an off-the-shelf computational 'widget' such as Brent's Method. Enjo's widget does the job well here, I'm sure.

It is easier, though, to drive the equation in reverse: instead of solving for 'r' as a function of 'time', we can easily solve for 'time' as function of 'r'. In fact, as written, that's exactly what the equation does. The left-hand-side is just 'time'; and the right-hand-side is just a function of 'r' - albeit a messy one.

For example, let's suppose that one wants to calculate the time it will take after the retrograde burn to hit the ground. And let's use the same scenario as before - i.e., starting a 20 x 20 km circular orbit around the moon, the craft executes a periapsis lowering retrograde burn that lowers the orbital periapsis altitude to -20 km. When does the spacecraft impact the surface?

To answer this question, we basically just need to plug the mean radius of the Moon is the right-hand-side as 'r', crank the handle, and calculate the answer. But let's break the process down into its component tasks. First, we note that the equation can be written as:

[MATH]\Delta \tau =A \times\left(\pi -2 \left(B(r)-C(r)\right)\right)[/MATH]
where

[MATH]A = \sqrt{\frac{\left(r_a+r_p\right){}^3}{8 \mu }}[/MATH]
[MATH]B(r) = \tan ^{-1}\left(\sqrt{\frac{r-r_p}{r_a-r}}\right)[/MATH]
[MATH]C(r) = \frac{\sqrt{\left(r_a-r\right) \left(r-r_p\right)}}{r_a+r_p}[/MATH]
Here, 'A' is just a constant. For the specific example that we are using with [MATH]r_a=1758100\,m[/MATH]; [MATH]r_p=1718100\,m[/MATH]; and [MATH]\mu=4.90487\times 10^{12}[/MATH] so that [MATH]A=1034.66[/MATH]. You might recognise that 'A' is closely related to the orbital period such that [MATH]T=2\,\pi\,A[/MATH] and all that the factor 'A' is doing here is converting the rest of the right-hand-side to units of time - i.e., its a conversion factor.

The rest of the right-hand-side - the [MATH]\pi -2 \left(B(r)-C(r)\right)[/MATH] bit - is just Kepler's Equation in disguise. Rather than deal with the eccentric anomaly and orbital eccentricity, it has just converted everything to expressions that just involve [MATH]r_a[/MATH], [MATH]r_p[/MATH] and 'r' - which are the things that we probably already know.

[MATH]B(r)[/MATH] and [MATH]C(r)[/MATH] are functions of the transfer radius, 'r'. If we want to know the time to impact, then, we just have to plug in values of [MATH]r_a[/MATH], [MATH]r_p[/MATH] and [MATH]r[/MATH]. In this case, the value of 'r' that we want to use is [MATH]1738100\,m[/MATH] - i.e., the Moon's mean radius. To calculate [MATH]B(r)[/MATH] we need to use the inverse tan function. This is found on most calculators and spreadsheets. One rarely calculates it 'by hand'. Sometimes it is called 'atan' or 'arctan'.

Anyway, if we plug in the values into the expression for [MATH]B(r)[/MATH], we get the value [MATH]0.785398[/MATH]. And if we plug in the values for [MATH]C(r)[/MATH] we get the value [MATH]0.00575341[/MATH]. So, then, the value of [MATH]\pi -2 \left(B(r)-C(r)\right)[/MATH] is [MATH]3.14159 - 2 \times (0.785398 -0.00575341) = 1.5823[/MATH]. And, so, to calculate [MATH]\Delta \tau[/MATH], the time to impact with the surface, we multiply this number by the value of 'A' (i.e., 1034.66) and get: [MATH]\Delta \tau = 1034.66 \times 1.5823 = 1637.14[/MATH]. So, the time to impact after the periapsis lowering burn is 1,637.14 seconds.

Now, there is nothing special about the value 'r' that we have chosen We could have chosen any other value of 'r' and thereby calculated the time taken to pass through the corresponding orbital altitude. The inversion of this process, calculating 'r' as a function pf 'time', is the tricky bit. Basically a root finding algorithm is needed and all these algorithms work in more or less the same way. They take an initial guess at 'r' and work out the corresponding value for [MATH]\Delta \tau[/MATH]. If that value doesn't equal the target value of [MATH]\Delta \tau[/MATH] - e.g. 1000 seconds, say - then the algorithm makes an intelligent update of the guess for 'r' and tries again. And the algorithm keeps on going through this process until it guesses right. Rather than invent their own guessing mechanism, most people most of the time just use other people's previously developed guessing mechanisms - hence Enjo's suggestion that you might want to try his which is based on a popular method, Brent's Method.

Feel free to ask questions about this. Everything is open for discussion.

---------- Post added at 10:11 AM ---------- Previous post was at 03:26 AM ----------

Actually, there is an easier way of calculating 'r' as a function of 'time'. The technique is to calculate a series expansion for 'r' in terms of [MATH]\Delta \tau[/MATH]. Such that:

[MATH]r = \alpha_0 + \alpha_2\,\Delta \tau^2 + \alpha_4\,\Delta \tau^4 + \alpha_6\,\Delta \tau^6 + \alpha_8\,\Delta \tau^8 + \alpha_{10}\,\Delta \tau^{10} + \dots[/MATH]
If one goes through the maths (and it helps to use a tool such as Mathematica or Matlab here), one can show that [MATH]\alpha_0[/MATH] is just your starting altitude when you execute the retrograde burn to lower periapsis and:

[MATH]\alpha_2 = \frac{\mu \left(-r_a+r_p\right)}{2 \,r_a^2 \left(r_a+r_p\right)} [/MATH]
[MATH]\alpha_4 = -\frac{\mu ^2 \left(r_a-2 \,r_p\right) \left(r_a-r_p\right)}{12 \,r_a^5 \left(r_a+r_p\right){}^2}[/MATH]
[MATH]\alpha_6 = -\frac{\mu ^3 \left(r_a-r_p\right) \left(11 \,r_a^2-44 \,r_a r_p+35 \,r_p^2\right)}{360 \,r_a^8 \left(r_a+r_p\right){}^3}[/MATH]
[MATH]\alpha_8 = -\frac{\mu ^4 \left(r_a-r_p\right) \left(73 \,r_a^3-438 \,r_a^2 r_p+714 \,r_a r_p^2-350 \,r_p^3\right)}{5040 \,r_a^{11} \left(r_a+r_p\right){}^4}[/MATH]
[MATH]\alpha_{10} = -\frac{\mu ^5 \left(r_a-r_p\right) \left(3548\, r_a^4-28384 \,r_a^3 r_p+70653 \,r_a^2 r_p^2-70840 \,r_a r_p^3+25025\, r_p^4\right)}{453600 \,r_a^{14} \left(r_a+r_p\right){}^5}[/MATH]
These 5 easy to calculate terms approximate 'r' to millimetre accuracy for the example used earlier. Additional terms can be calculated, but I doubt that they would be needed in most circumstances.
 
Last edited:

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,669
Reaction score
797
Points
128
That might be easier to compute by using more traditional methods.
For an example radius is

r = a ( 1 - e * cos(E) )

and

M = E - e * sin(E)

where,

dM = dT * sqrt( |a^3| / u )

M = mean anomaly
E = eccentric anomaly
T = time
a = semi-major axis
e = eccentricity
r = orbital radius
u = gravitational parameter GM

Biggest problem is solving the equation M=E-esin(E) for E to get the E from initial M + dM. It is usually solved by using a newtons method. (Taking about 8 short lines of code.)

---------- Post added at 21:38 ---------- Previous post was at 21:33 ----------

By the way, have you successfully computed the equations from the last few pages of Orbiter manual "26.1 Calculating elements from state vectors" ?

---------- Post added 27-01-16 at 15:10 ---------- Previous post was 26-01-16 at 21:38 ----------

Solving the equation M = E - e*sin(E) for E using newtons method is pretty simple. We cannot directly compute the value of 'E' so we have to guess. For a circular orbit E = M, so that's pretty good initial guess for 'E'. Then we need an iteration loop to improve the guess. Whit-in the iteration loop we have to evaluate the 'M' that is given by the latest guess of 'E'.


PHP:
double E = M;  // Initial guess of E

for (int i=0;i<32;i++) {
	
	double m = E - e*sin(E);	// value of M given by the latest guess of E
	double s = M - m;		// How far we are from the input value M

}

Now we know how far we are from the solution but we don't know how fast the function is changing, so, we don't know how to change the guess. The answer to the problem is 1st differential of M = E-e*sin(E) that will give the rate of change and that is:

d = 1.0 - e * cos(E)

Now we have the means to improve the guess properly and efficiently:


PHP:
double E = M;  // Initial guess of E

for (int i=0;i<32;i++) {
	
	double m = E - e*sin(E);	// value of M given by the latest guess of E
	double d = 1.0 - e * cos(E);	// 1st Differential of M = E-e*sin(E) 
	double s = M - m;		// How far we are from the input value M
	E += s/d;			// Improve the guess
}


The number of times the loop needs to run depends from the case. Usually (1-32). We can improve the algorithm by looping as long is needed to get the 's' reasonably close to zero.


PHP:
// Solve E form M = E - e*sin(E)
//
double E_by_M(double M, double e)
{
double E = M;  // Initial guess of E
double s = 1;
while (fabs(s)>1e-12) 
{	
	double m = E - e * sin(E);	// value of M given by the latest guess of E
	double d = 1.0 - e * cos(E);	// 1st Differential of M = E-e*sin(E) 
	s = M - m;			// How far we are from the input value M
	E += s/d;			// Improve the guess
}

return E;
}

NOTE: I haven't tested the algorithm and it doesn't work with hyperbolic trajectories. I can copy-paste some code from my works if you need.
 
Last edited:

Bud

Tutorial Publisher
Tutorial Publisher
Joined
Nov 17, 2008
Messages
8
Reaction score
0
Points
0
Using the first formula provided by Keithth I seem to have a problem calculating B.

using the formula I get the correct values for A and C:

[math] A = 1034.66 [/math][math] C = 5.75X10^{-3} [/math]

for B I get:

[math] (r - r_p) / (r_a - r) = (1738100 - 1718100) / (1758100 - 1738100) = 20000/20000 = 1 [/math]
[math] \sqrt{1} = 1 [/math]
[math] tan^{-1}1 = 45 [/math]
rather than 0.785398 you have.

Where am I going wrong with calculating B?
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
Hi, Bud

The [MATH]\sin^{-1}[/MATH], [MATH]\cos^{-1}[/MATH] and [MATH]\tan^{-1}[/MATH] return numbers in radians - not degrees. So, yes, 'B' evaluates to 45 degrees but you need to convert this to radians. And you do this by multiplying the '45' by [MATH]\frac{\pi}{180}[/MATH]. This should now give the right answer.

I should have pointed that out. Sorry for the confusion.
 
Last edited:

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
Using the first formula provided by Keithth I seem to have a problem calculating B.

using the formula I get the correct values for A and C:

[math] A = 1034.66 [/math][math] C = 5.75X10^{-3} [/math]

for B I get:

[math] (r - r_p) / (r_a - r) = (1738100 - 1718100) / (1758100 - 1738100) = 20000/20000 = 1 [/math]
[math] \sqrt{1} = 1 [/math]
[math] tan^{-1}1 = 45 [/math]
rather than 0.785398 you have.

Where am I going wrong with calculating B?

Radians, my friend...

You'll find almost everything is done internally in radians, and the convert to degrees (i.e. * DEG) is just for end users.
 

perseus

Addon Developer
Addon Developer
Joined
May 31, 2008
Messages
316
Reaction score
1
Points
18
orbitabase1.jpg


I think what you need is this the point of the orbit would be in polar coordinates (R, θ)

Depending on the radius at the height and speed in this

R=f(θ,v1,R1)

V1 = speed apoapsis or periapsis
R1 = radius apoapsis or periapsis
M = Central Mass
θ = elongation from the apoapsis

R = V1^2. R^2 / {GM (1-cos (θ)) + V1. R1.cos (θ)}

I hope you find it useful
 
Last edited:

Bud

Tutorial Publisher
Tutorial Publisher
Joined
Nov 17, 2008
Messages
8
Reaction score
0
Points
0
Radians, of course. Oops!
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
Another good series expansion for [MATH]r[/MATH] as a function of time is:

[MATH]r = r_0 + a\,e\,(1-\cos(\omega\,\Delta\tau)) - \frac{1}{2}\,a\,e^2\,(1-\cos(2\,\omega\,\Delta\tau)) +\frac{3}{8} \,a\,e^3\,(1-\cos(3\,\omega\,\Delta\tau))+\dots[/MATH]
where

[MATH]a = \frac{r_a+r_p}{2}[/MATH]
[MATH]e = \frac{r_a-r_p}{r_a+r_p}[/MATH]
[MATH]\omega = \sqrt{\frac{\mu}{a^3}}[/MATH]
and where [MATH]r_0[/MATH] is the starting altitude when the periapsis burn is executed. This series is, in effect, a fourier expansion of the solution of Kepler's equation.

For the example above, this is accurate to less than 1 m - and is valid for the entire orbit. Higher order terms can be calculated if needed.
 
Last edited:
Top