Jump to content

Orbit.getOrbitalVelocityAtUT()  returns rotated vector after each Quickload, with the same argument


Recommended Posts

Hi! I am trying to calculate the velocity (with direction) at a certain point later in the orbit.

I am trying to read this with this with Orbit.getOrbitalVelocityAtUT()           

Vector3d orbitalVelocityAtImpact = vessel.orbit.getOrbitalVelocityAtUT(impactUT);


However, something very strange is occurring:

I quickload a save, and proceed along the Orbit for a few in-game minutes. Then I reload the save from where I started. But the Orbital Velocity has changed direction! I presume it is still in the state before the quickload.

Here are three values that I recorded right after quickloading:

+        orbitalVelocityAtImpact    "[169.909714097467, 29.454900938199, 10.8833349871162]"    Vector3d
+        orbitalVelocityAtImpact    "[171.443843360678, 18.5448866639756, 10.8833496607608]"    Vector3d
+        orbitalVelocityAtImpact    "[172.27266602452, 7.68307916777123, 10.8833286528833]"    Vector3d

As you can see, the velocity keeps rotating. This is with the argument of the function (the time) staying approximately the same. I am confused :confused:

@Starstrider42 was onto something here, and he mentioned something about Planetarium.Zup quaternions.

 

Unfortunately, I have no idea what Planetarium.Zup is, how it changes, how it relates to Orbit.getOrbitalVelocityAtUT(), and how to use it to fix my rotations.

Can you guys help me out here?

Link to comment
Share on other sites

Sorry for stating the obvious but orbit are not straight lines. The velocity will rotate with time. You do not state the time difference between each samples.

Try with GetOrbitalStateVectorsAtUT 

Link to comment
Share on other sites

47 minutes ago, sarbian said:

Sorry for stating the obvious but orbit are not straight lines. The velocity will rotate with time. You do not state the time difference between each samples.

The difference between the samples is zero.

  1. Quicksave.
  2. Observe Value
  3. Timewarp 5 ingame minutes
  4. Quickload
  5. Observe Value
  6. Timewarp 5 ingame minutes
  7. Quickload
  8. Observe Value

If I observe the value right after quickloading, it should be the same every single time, shouldn't it? Nothing inside the game universe changes.

Quote

Try with GetOrbitalStateVectorsAtUT 

Thanks, I will try that!

By the way, I actually just care about the surface-relative velocity at the UT, so if there's a shortcut for that that would also work.

edit: Just tried GetOrbitalStateVectorsAtUT(), returns a different value than getOrbitalVelocityAtUT() but it also drifts across reloads.

Edited by Kobymaru
Link to comment
Share on other sites

Ok, update:

I "solved" my issue.

Turns out that both  GetOrbitalStateVectorsAtUT and getOrbitalVelocityAtUT return a value in some weird reference frame that rotates, but doesn't rotate back when quickloading.

In my application, I only needed the angle between the the up direction and the velocity at the time of impact. For this, I could simply take position and velocity vectors returned by GetOrbitalStateVectorsAtUT, and calculate the angle between those, since the position vector was the local frame but rotated in the same way as the velocity vector.

Link to comment
Share on other sites

  • 6 months later...
On 4/4/2017 at 10:42 AM, Kobymaru said:

Turns out that both  GetOrbitalStateVectorsAtUT and getOrbitalVelocityAtUT return a value in some weird reference frame...

That's the inverse rotation, when you're under the inverse rotation threshold.

Working code to update an orbit and then get the state vectors at some future time looks something like this:


private void CSEKSP(Vector3d r0, Vector3d v0, double t, out Vector3d rf, out Vector3d vf)
            Vector3d rot = orbit.GetRotFrameVelAtPos(mainBody, r0.xzy);
            CSEorbit.UpdateFromStateVectors(r0.xzy, v0.xzy + rot, mainBody, vesselState.time);
            CSEorbit.GetOrbitalStateVectorsAtUT(vesselState.time + t, out rf, out vf);
            rot = orbit.GetRotFrameVelAtPos(mainBody, rf);
            rf = rf.xzy;
            vf = (vf - rot).xzy;
}

Only the velocity vector gets fixed like this, the position vectors don't need correcting.  Above the inverse rotation threshold GRFVAP returns Vector3d.zero.  

Sorry for the necro, but I wanted to update this thread with the information for search engines in case anyone else hits this.

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...