Jump to content

Orbit state vectors not reproducible?


Recommended Posts

I found something weird when trying to debug a new feature in Custom Asteroids (https://github.com/Starstrider42/Custom-Asteroids/issues/26). Can somebody explain this to me?

  1. Load Custom Asteroids with the following config only:
    Spoiler

    AsteroidSets
    {
        ASTEROIDGROUP
        {
            name = xy
            title = X-Y Plane

            centralBody = Sun

            spawnRate = 1.0

            orbitSize
            {
                type = SemimajorAxis
                min  = Ratio(Jool.sma, 0.9)
                max  = Ratio(Jool.sma, 0.9)
            }

            inclination
            {
                avg = 0
            }

            periapsis
            {
                type = Longitude
                min = 90.0
                max = 90.0
            }

            ascNode
            {
                min = 90.0
                max = 90.0
            }

            orbitPhase
            {
                type = MeanLongitude
                epoch = Now
                min = 0.0
                max = 0.0
            }
        }

    }

    (For those not familiar with CA config syntax, this creates asteroids on a fixed orbit, always spawning at the same place).

  2. Start a new KSP (1.1.0) game and let the spawner log the orbital elements and state vectors of new asteroids:

    Spoiler

    orbit: a = 61896183895.8152 m, e = 0, i = 0, argPe = 0, lAn = 90, mEp = -1.5707963267949 at epoch 84989.5893112183
    UT = 84989.5893112183
    x_0 (relativePositionAtUT) = [-39771554371.5685, 47427429233.872, 0]
    v_0 (orbitalVelocityAtUT) = [-3334.71870588347, -2796.41900991061, 0]
    x_0 (positionAtUT) = [-48493074463.4069, 1014.90997314453, 57861748376.7216]
    x_0 (truePositionAtUT) = [-48493074463.4069, 1014.90997314453, 57861748376.7216]
    v_0 (frameVelAtUT) = [-3334.71870588347, -2796.41900991061, 0]

    orbit: a = 61896183895.8152 m, e = 0, i = 0, argPe = 0, lAn = 90, mEp = -1.5707963267949 at epoch 219281.928708191
    UT = 219281.928708191
    x_0 (relativePositionAtUT) = [-39771554371.5685, 47427429233.872, 0]
    v_0 (orbitalVelocityAtUT) = [-3334.71870588347, -2796.41900991061, 0]
    x_0 (positionAtUT) = [-48493074463.4069, 1014.90997314453, 57861748376.7216]
    x_0 (truePositionAtUT) = [-48493074463.4069, 1014.90997314453, 57861748376.7216]
    v_0 (frameVelAtUT) = [-3334.71870588347, -2796.41900991061, 0]

     

  3. Exit KSP, restart KSP, load the game from step 2, and let some more asteroids spawn:

    Spoiler

    orbit: a = 61896183895.8152 m, e = 0, i = 0, argPe = 0, lAn = 90, mEp = -1.5707963267949 at epoch 330370.966731021
    UT = 330370.966731021
    x_0 (relativePositionAtUT) = [39152943915.2026, -47939384264.2724, 0]
    v_0 (orbitalVelocityAtUT) = [3370.71554502888, 2752.92296311742, 0]
    x_0 (positionAtUT) = [49392906256.6498, 1014.90997314453, -56890084838.7397]
    x_0 (truePositionAtUT) = [49392906256.6498, 1014.90997314453, -56890084838.7397]
    v_0 (frameVelAtUT) = [3370.71554502888, 2752.92296311742, 0]

    orbit: a = 61896183895.8152 m, e = 0, i = 0, argPe = 0, lAn = 90, mEp = -1.5707963267949 at epoch 455458.894602115
    UT = 455458.894602115
    x_0 (relativePositionAtUT) = [39152943915.2026, -47939384264.2724, 0]
    v_0 (orbitalVelocityAtUT) = [3370.71554502888, 2752.92296311742, 0]
    x_0 (positionAtUT) = [49392906256.6498, 1014.90997314453, -56890084838.7397]
    x_0 (truePositionAtUT) = [49392906256.6498, 1014.90997314453, -56890084838.7397]
    v_0 (frameVelAtUT) = [3370.71554502888, 2752.92296311742, 0]

     

The tracking station shows the asteroids spawning on the same orbit in the same spot. The orbital elements are identical. Yet the state vectors have not only absolute values different by about a percent, but OPPOSITE SIGNS in the two sessions. Why is this?

In case anybody wants it, the code behind the logging:

Spoiler

double ut = Planetarium.GetUniversalTime();
Vector3d x = orbit.getRelativePositionAtUT(ut);
Vector3d v = orbit.getOrbitalVelocityAtUT(ut);

Debug.Log("Transforming orbit from frame " + plane);
Debug.Log("orbit: a = " + orbit.semiMajorAxis + " m, e = " + orbit.eccentricity + ", i = " + orbit.inclination
    + ", argPe = " + orbit.argumentOfPeriapsis + ", lAn = " + orbit.LAN + ", mEp = " + orbit.meanAnomalyAtEpoch + " at epoch " + orbit.epoch);
Debug.Log("UT = " + ut);
Debug.Log("x_0 (relativePositionAtUT) = " + x);
Debug.Log("v_0 (orbitalVelocityAtUT) = " + v);
Debug.Log("x_0 (positionAtUT) = " + orbit.getPositionAtUT(ut));
Debug.Log("x_0 (truePositionAtUT) = " + orbit.getTruePositionAtUT(ut));
Debug.Log("v_0 (frameVelAtUT) = " + orbit.GetFrameVelAtUT(ut));

 

Edited by Starstrider42
Link to comment
Share on other sites

For those who might stumble across this post later:

It turns out that, while the coordinates do change between game instances, KSP always handles them self-consistently in the sense that the statement

orbit.UpdateFromStateVectors(orbit.getRelativePositionAtUT(ut), orbit.getOrbitalVelocityAtUT(ut), orbit.referenceBody, ut);

never changes the orbit. However, the coordinates are in the frame given by Planetarium.ZupRotation, so any attempts to transform those coordinates need to include rotations by ZupRotation and/or its inverse.

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