Determining speed relative to surface (ground speed)

Thorsten

Active member
Joined
Dec 7, 2013
Messages
785
Reaction score
56
Points
43
So I guess we ought to chalk it up to my general ignorance (me getting too old for king of the hill games...)
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
So I guess we ought to chalk it up to my general ignorance (me getting too old for king of the hill games...)
I'm also perfectly willing to chalk it up to the way the forum only displays the first 30 or so characters of a thread title in the "unread" list even though it has plenty of rom to display the full thing; I've been caught by that before :lol:
 

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
I have been working on a simulation and have got a spaceship in orbit around a planet. Now I want to present some information useful for navigation, in particular for landing on the surface. So the speed the surface moving under you is important, but for the life of me I can not figure it out or find the right information on the web (or the math forum)

I have two hunches. The first is that I need to find the tangential plane to the surface of the planet and project the velocity vector onto this plane, which will match the vector you find in this plane for the velocity of the rotation of the body. This is not a simple orthogonal projection though, so there I get stuck.

My second hunch is that there's a chance converting the vector represention to Kepler elements might be better, scaling the distance between two moments in time to the circle the ship orbits, but perhaps this is only easier in the idealised circular, non inclined orbit. (Isn't everything?)

Some details:

This simulation is running on a 1mhz Commodore 64, so it's highly likely the code to calc the speed, will take as long as updating the physics, I might have to forego considering the rotation speed, but basically the point is I am looking for a method that is both computationally cheap, and memory friendly. Approximations are okay, because of the resoloution of the dimensions, you'll be landing at unrealistic speeds anyway. I have slow and accurate trig routines, and fast and approximate ones, so with lots of fast trig the errors compound.

Any pointers are appreciated. Nice to be on this forum, and hope to have anyone interested flying an 8-bit spaceship soon.


Hi, 'malcontent'

I've been following this thread off and on for the last few weeks. Here's an approach to your problem that you may want to consider.

As I understand it, you have developed an integration engine that reproduces a normal Keplerian (i.e., circular, elliptical, parabolic or hyperbolic orbit) around a planet. For the most part, these integration schemes tend to be set up in an inertial reference frame. For many problems, the choice of an inertial reference frame makes ensuing calculations simpler. However, for some problems - and possibly for your problem - using an integration scheme in inertial space makes life harder.

It is always possible, though, to set up a numerical integration scheme in a reference frame that co-rotates with the planet such that all points on the planet have a fixed position. In the past (and largely form my own amusement), I've developed a number of explicit symplectic integration schemes that work in these rotating reference frames. Since, the position of all points on the surface of the planet are fixed, determining the speed of your vessel with respect to a (now stationary) point directly underneath your vessel can be calculated using straightforward projective geometry. At worst, this calculation involves an inverse square root calculation which is something that you can already calculate reasonably cheaply.

As far as the symplectic integrator is concerned only simple arithmetic calculations are required (i.e., no sine or cosine evaluations); and can be constructed as a second order, fourth order or higher order integrator as desired.

If this is of interest to you, I'll post the second-order symplectic integrator (in 3D, rotating coordinates) so that you can play around with it and see if it meets your requirements. If you need higher order integration schemes, I can show you how to combine the second-order scheme to construct higher-order schemes.

P.S. If you also require the integrated trajectory in inertial coordinates (as well as rotating coordinates) then rather convert between inertial and rotating reference frames, the easier thing to do may be to perform two parallel integrations - one in inertial coordinates; and one in rotating coordinates.

---------- Post added 02-28-17 at 03:03 AM ---------- Previous post was 02-27-17 at 06:54 AM ----------

For anyone interested, here is a Lua script for a numerical integration of an orbit around a planet (in this case, the Earth) in rotating coordinates and calculating the grounds speed of the vessel without using sines and cosines.

The inputs to the integration are the position and the velocity of the vessel in rotating coordinates. In the specific example given below, the vessel is in a 300 x 300 km polar orbit starting from the equator and heading North towards the pole. In inertial coordinates, this means that it should be orbiting at around 7725.839 m/s, but in rotating coordinates it also picks up a perpendicular component due to the rotation of the Earth of -486.967 m/s.

The integration engine here is a simple second-order (symplectic) integrator. Higher order integrators can easily be constructed from this using the scheme given here http://www.orbiter-forum.com/showthread.php?t=35489&highlight=symplectic

The integrator requires one inverse square root calculation per time-step; and to calculate the ground speed, one further inverse square root calculation is required and one sort calculation. All other operations are simple arithmetic operations +, -, * , / . No sines or cosines are required.

Although written in Lua, it should be easy to convert to other programming languages.

It is should also be easy to calculate ground tracks using the same algorithm,



Code:
-- enter a few specific details for the planet, in this case 'the Earth'
GM  = 3.986004418e14                      -- standard gravitational parameter 
R   = 6378000.0                           -- mean radius of the Earth
w   = 2 * math.pi / (86400 * 0.99726958)  -- Earth's sidereal rate of rotation 

-- enter some numerical integration constants
dt  = 10                                   -- integration time-step  
phi = w * dt                               -- the product of rate of rotation and the time step

-- define the second-order symplectic integrator - for rotating coordinates
integrator = function (Q0, V0)
 
  -- initialise some quantities used for internal calculation
  local iphi = 0
  local rho  = 0
  local rho3 = 0
  local irho3= 0
  local Qa   = {x = 0, y = 0, z = 0}
  local Q1   = {x = 0, y = 0, z = 0}
  local V1   = {x = 0, y = 0, z = 0}
  local  F   = {x = 0, y = 0, z = 0}
  
  
  -- the first part of the leap-frog integration scheme
  Qa.x = Q0.x + 0.5 * dt * V0.x
  Qa.y = Q0.y + 0.5 * dt * V0.y
  Qa.z = Q0.z + 0.5 * dt * V0.z
  
  
  -- the second part of the leap-frog integration scheme
  rho  = 1 / math.sqrt( Qa.x * Qa.x + Qa.y * Qa.y + Qa.z * Qa.z)
  irho3= rho * rho * rho
  iphi = 1 / (1 + phi * phi)
  
  F.x  = - GM * Qa.x * irho3 + w * w * Qa.x           -- inverse square law and centrifugal force
  F.y  = - GM * Qa.y * irho3 + w * w * Qa.y           -- inverse square law and centrifugal force
  F.z  = - GM * Qa.z * irho3                          -- inverse square law only
  
  V1.x = ( (1 - phi * phi) * V0.x + 2 * phi * V0.y + dt * (F.x + phi * F.y)) * iphi
  V1.y = (-2 * phi * V0.x + (1 - phi * phi) * V0.y + dt * (F.y - phi * F.x)) * iphi
  V1.z = V0.z + dt * F.z


  -- the third part of the leap-frog integration scheme
  Q1.x = Qa.x + 0.5 * dt * V1.x
  Q1.y = Qa.y + 0.5 * dt * V1.y
  Q1.z = Qa.z + 0.5 * dt * V1.z
  
  
  -- return the result of the integration step
  return Q1, V1

end


groundSpeed = function (Q, V)
  local gspd   = 0.0
  local rhat   = {x = 0.0, y = 0.0, z = 0.0}
  local Vw     = {x = 0.0, y = 0.0, z = 0.0}
  local Vrhat  = 0.0
  local inormQ = 0.0
  
  inormQ  = 1 / math.sqrt(Q.x * Q.x + Q.y * Q.y + Q.z * Q.z)
  rhat.x  = Q.x * inormQ
  rhat.y  = Q.y * inormQ
  rhat.z  = Q.z * inormQ
  
  -- calculate the projection of the velocity vector onto the Earth's surface
  Vrhat   = V.x * rhat.x + V.y * rhat.y + V.z * rhat.z
  Vw.x    = (V.x - rhat.x * Vrhat) * inormQ * R
  Vw.y    = (V.y - rhat.y * Vrhat) * inormQ * R
  Vw.z    = (V.z - rhat.z * Vrhat) * inormQ * R
  
  gspd    = math.sqrt(Vw.x * Vw.x + Vw.y * Vw.y + Vw.z * Vw.z)
  
  return gspd
end


-- set up the initial conditions for position and velocity in rotating coordinates
Q = {x = 6678000.0, y = 0.0, z = 0.0}
V = {x = 0.0, y = -486.96749, z = 7725.83948}

print( groundSpeed (Q, V))
for idx = 1, 400 do
  Q, V = integrator(Q, V)
  print( groundSpeed (Q, V))
end
 
Last edited:

malcontent

Off on a Comet
Joined
Feb 15, 2017
Messages
27
Reaction score
11
Points
18
This is very cool! A little over my head but seems perfectly doable.

Let me describe my simulator in a little more detail because this brings up a problem I was going to start another topic on.

The sim has 3 bodies. Earth, which is at the origin, a moon, and a ship. The integrator is indeed what you call the "leap frog." It only uses one-step though. The problem is I have no idea what my units are. Basically I have placed the moon at 384,0,0, gave it a y velocity of .7488, timestep of .0258, and set the values of g*m1*m2 to .280327451. the odd numbers were just trial and error until I got a circular orbit at a scaled distance similar to the moon. Nothing is controllable at the moment, everything just trundles around.

I have code that draws a trajectory from Kepler elements (hopefully for navigation purposes), but to be any use requires I know what I've basically ignored when I cludged together the description of the Cartesian frame.

So basically how do I figure out what G is, and how do I "scale" my gravity formula? For example, I have an idea that to save a multiplication, a time step of 1 makes .5*dt*x become x/2 which is just decrementing a floating-point exponent. But G has time in its units so clearly it has to change too if the simulation is to behave just as before. Likewise I do something rather inefficient that I'd like to change. At the end of the calcs, the numbers are scaled by 10 then the display code shrinks it if the view is zoomed out. I'd rather just scale my distances by 10, but again this changes G as well I think.

Eventually it will be able to accept real world values and use them, even if the results aren't the same because of inaccuracies, but ideally the elements will be user definable.
 
Last edited:

Keithth G

New member
Joined
Nov 20, 2014
Messages
272
Reaction score
0
Points
0
So basically how do I figure out what G is, and how do I "scale" my gravity formula? For example

Hi, 'malcontent', to do the scaling, you need to set a scale for mass, distance and time. Suppose 'M' is the mass of the gravitating body (in your case, the Earth); 'T' is the orbital period; and 'R' is the radius of the much smaller secondary body (the Moon) from the primary body (the Earth). In this case, if you choose units such that R = 1; G * M = 1; and T = 2 * pi; the orbital speed of the secondary body in a circular orbit around the primary will be 1 (i.e., V = 1).

Now, let's suppose that you wish to reset the scale for distance such that R' = 384. A re-scaling of distance will not affect the orbital period (simply measuring things in feet rather than meters isn't going to change the amount of time the Moon takes to orbit the Earth). However, for this to be true, we need to rescale the product GM to GM', such that GM' = GM * 384^3 = 384^3. And now, of course V has also needs to be re-scaled and the new, rescaled circular orbital speed is given by V' = V * 384 = 384.

And let's suppose that you want also want to re-scale time so that the orbital period is, for sake of example, 28 (days). In this case T' = 28 = (28/2/pi) * T. Again, we need to adjust the product GM' and the orbital speed V'. The scaling rules here are:

GM'' = GM' / (28/2/pi)^2 = 384^3 / (28/2/pi)^2 = 2851263.45

and

V'' = V' / (28/2/pi) = 384 / (28/2/pi) = 86.169398

A couple of points:

1. The thing that you really need to calculate is the product G*M not G*M*m (where 'm' is the mass of the orbiting body). The mass, m, cancels out in the equations of motion, so regardless of the mass of the object (so long as it isn't big in comparison with the Earth) will follow the same path. (I think it was Galileo who first proposed this notion - but it was graphically demonstrated by astronauts on the Moon in the early 70s who repeated, somewhat informally, Galileo's famous 'feather and cannonball' experiment in a vacuum.)

2. In actual fact, the Moon is reasonably large in comparison with the Earth. So, in as much as the Moon orbits the Earth, the Earth also orbits the Moon. This means that instead of using G * M in the equations, you should really be using G * (M+m). Or, in other words, you need to add the mass of the Moon to the mass of the Earth to get the effective gravitational mass that the Moon 'sees' in its orbit around the Earth. The Moon's mass is about 1/82 of the Earth's.

3. In your integration scheme, you are assuming that the Earth is located at the origin. In a standard inertial reference frame, however, it doesn't. Instead, it like the Moon will orbit the Earth-Moon centre of mass once every 28 days or so, with an orbital radius of about 6,000 km. Having said that, there is nothing wrong with choosing to locate the Earth at the origin, but you should note that this choice of reference frame gives rise to some additional (small) force terms in your equations of motion that if you want high accuracy in your simulation you should properly take note of. But for the time being, you can probably ignore these.
 
Last edited:

malcontent

Off on a Comet
Joined
Feb 15, 2017
Messages
27
Reaction score
11
Points
18
This is great, you've given me a lot to think about. I have pretty much figured out that I will need the polar angles anyway. They're just too useful for other calculations that might occur in real-time, like attitude indication. It doesn't have to be accurate, it just has to fake accuracy. That said, when you point to something like an orbit normal direction it should be accurate enough and hopefully won't be jumping around too much.
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,218
Reaction score
1,566
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
Guess I should wrote that down?

:shrug:

Don't worry, we've figured out how to mass-restore all those deleted posts via a SQL command, and that should happen within the next day or two. So the deleted information will be restored soon. :thumbup:
 

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
...So the deleted information will be restored soon. :thumbup:
As much as I am painfully sorry to see Keithth_G's precious posts disappear (even if I understood a tiny fraction of them), shouldn't a user be free to edit - even delete - his/her own posts?
 
Last edited:

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
As much as I am painfully sorry to see Keithth_G's precious posts disappear (even if I understood a tiny fraction of them), shouldn't a user be free to edit - even delete - his/her own posts?

I think so, too. But keep in mind that regular users don't have the same information about the incident as admins/mods. Perhaps an imposter got hold of Keith's passwords and wrecked havoc, followed by Keith contacting staff here to set things straight again.

Many things are possible, so I guess we just have to be patient and let the involved parties work it out. I - for one - trust the mods to not do anything harmful to the community or the users here.
 

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
Sure, I didn't mean to criticize Mods attitude. My question was more about the "philosophical" side.
As you say, there may be more to it. I'm sure they'll sort it out for the best.

:cheers:
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,218
Reaction score
1,566
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
All 272 of the deleted posts have been mass-restored via a SQL command now (thanks, Orb!), so if you still notice any missing content, please PM a staff member.
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,218
Reaction score
1,566
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
As much as I am painfully sorry to see Keithth_G's precious posts disappear (even if I understood a tiny fraction of them), shouldn't a user be free to edit - even delete - his/her own posts?

The staff discussed the topic of users mass-deleting their own posts a few years ago back when the "delete post" button was still enabled, and the consensus was that once content is posted to the board it becomes part of the community and is therefore not the original poster's "property" to be mass-deleted to try to harm the community. This is why the "delete post" button was removed several years ago following that staff discussion: deleting helpful board content 1) creates "holes" in threads across the forum, and 2) harms the community as a whole. That doesn't help anybody, and that is why the staff works to keep the board intact in cases of board vandalism.
 

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?
While I'd like to have Keith's posts back, it's bad that you didn't at least wait for him to clarify what was going on. He might be for example treated by the Chinese government as a spy and go to prison because of that one SQL command...
 
Last edited:

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,218
Reaction score
1,566
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
To the staff's knowledge, so far Keith has not replied to anyone, even forum members he is friends with, about why he mass-deleted his posts and left the forum. If he messages the staff explaining why he did what he did, assuming he has a good reason for it, we would re-delete his posts in that case. However, if he was really in danger of "going to a Chinese prison as a spy" because of his posts on Orbiter-Forum, I would expect he would have told someone why he was deleting all his posts, or at least that he had a serious reason for doing it.

So far the only communication from Keith to the staff was a request that the staff close his account (i.e., make it so nobody can log in using it any longer), which we have done. Speaking from experience, 99.9% of the time when that occurs the OP is angry about something.
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
I think that the mods have handled this difficult situation in an exemplary manner, with thoughtful and logical process and due sensitivity to the rights of the individual and the needs of the community for valuable information imparted by Keith.

To Keith individually - please get a message to the mods or to me privately to let us know you are OK. You have many friends here, and we are all concerned about you. Our best wishes to you and your family and friends.
 

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?
To the staff's knowledge, so far Keith has not replied to anyone, even forum members he is friends with, about why he mass-deleted his posts and left the forum.
I can confirm this.

So far the only communication from Keith to the staff was a request that the staff close his account (i.e., make it so nobody can log in using it any longer), which we have done. Speaking from experience, 99.9% of the time when that occurs the OP is angry about something.
... experience with members living in the Free World, mind you. Chinese communists are brainwashed maniacs who won't (/don't want to) understand, that we're just having fun with maths. We've had this in Poland too.

If he messages the staff explaining why he did what he did, assuming he has a good reason for it, we would re-delete his posts in that case. However, if he was really in danger of "going to a Chinese prison as a spy" because of his posts on Orbiter-Forum, I would expect he would have told someone why he was deleting all his posts, or at least that he had a serious reason for doing it.
That's a good compromise. I'll let him know. Cheers.:cheers:
 
Last edited:

malcontent

Off on a Comet
Joined
Feb 15, 2017
Messages
27
Reaction score
11
Points
18
I too was wondering if it might have been due to his location, there are many curbs on the Chinese internet, Hong Kong in spite of its relative autonomy is not immune. If it was for his safety it's reasonable, but of course surely that's something admins could have done for him. At least on the forum I administrate there's a way to delete all of a user's posts.

Of course the real lesson (by Google cache) is basically if you don't want it to remain on the WWW don't put it there in the first place.
 
Top