Jump to content

Trying to understand orbit position vectors.


Recommended Posts

The long version is below, but the short form of my question is:

How can I use vessel.orbit to find out what latitude and longitude a vessel will be at, at some specified UT time?

 

So, let's say I'm interested in getting the current position of a vessel, relative to the planet it's on.  Here are a couple of ways I could do that:

  1. Take vessel.latitude and vessel.longitude, and do math with that.
  2. Take vessel.orbit, and get the vessel's position at the current UT.

I ought to be able to do either of those two methods, and come up with the same answer in both cases, doing some trigonometry and vector manipulation and such.  However, I'm having a dickens of a time getting them to line up.

As far as I can tell by checking it against other things (e.g. checking PQS for terrain altitude), I believe my math around latitude/longitude is correct.

However... I'm doing something wrong with method #2, and haven't been able to work out where I'm going astray.

Here's an example of what doesn't work:

// Swap Y and Z axes because apparently KSP orbital calcs are funky that way
Vector3d relPosition = vessel.orbit.getRelativePositionAtUT(
    Planetarium.GetUniversalTime()).xzy;

// then do stuff with relPosition

I mean, if I do that, I get some position... but it appears to be telling me a very different answer for my location than if I use latitude/longitude.

It does appear to be surface-relative-- e.g. if I just sit stationary on the surface, it gives numbers that don't change.  It's just that it's telling me a different location.

For example, KSC is almost perfectly on the equator, located at around 75 degrees west longitude.

If I do the above bit with calculating relPosition, I don't get anything like that.  It does correctly put me at the expected latitude, but the longitude is screwy and I'm not sure why.  Furthermore, it's inconsistent-- let's say I launch, note the coordinates that relPosition is pointing me at, then I revert-to-launch, I get very different numbers as if I'm on a completely different part of the planet, even though the ship hasn't budged a centimeter.

Clearly I'm doing something wrong here, perhaps "getRelativePositionAtUT" is returning something different than I think?  But darned if I have any clue what that might be, or what else I should be calling.

Does anyone have any advice to offer?

Link to comment
Share on other sites

I'm not sure about RelativePositionAtUT, but SCANsat uses getPositionAtUT, along with a correction for rotation taking the current time vs the time being checked (the part about fixLon/Lat is just for clamping the values).

https://github.com/S-C-A-N/SCANsat/blob/release/SCANsat/SCANcontroller.cs#L2065-L2073

 

Edited by DMagic
Link to comment
Share on other sites

52 minutes ago, DMagic said:

I'm not sure about RelativePositionAtUT, but SCANsat uses getPositionAtUT, along with a correction for rotation taking the current time vs the time being checked (the part about fixLon/Lat is just for clamping the values).

https://github.com/S-C-A-N/SCANsat/blob/release/SCANsat/SCANcontroller.cs#L2065-L2073

 

Thank you!  Will see what I can cobble together using that approach.

Link to comment
Share on other sites

  • 1 month later...

Thanks.

So, a quick follow up : from my tests, it seems that correcting the longitude for the mainbody rotation is necessary only if the reference frame is rotating (below 100 Km altitude at Kerbin), not once you get in the inertial frame.

Edit : I'm dumb.

Edited by Gotmachine
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...