Jump to content

Create an orbit above current orbit


Recommended Posts

Hey,

I'm trying to create an orbit which is X meters above the current orbit. I am however not able to get it to work.

This is the code I got so far:

        private Orbit CreateOrbitAroundAndNear(CelestialBody body, Orbit nearOrbit, int minAltitude, int maxAltitude)
{
Orbit orbit = new Orbit();
orbit.referenceBody = body;
orbit.eccentricity = (double)UnityEngine.Random.Range(0.0001f, 0.01f);

orbit.semiMajorAxis = (double)UnityEngine.Random.Range((float)(body.Radius) + (float)minAltitude, (float)(body.Radius) + (float)maxAltitude);
orbit.inclination = (double)UnityEngine.Random.Range((-1.0f / 10.0f), 1.0f / 10.0f);

orbit.LAN = (double)UnityEngine.Random.Range(0.999f, 1.001f);

orbit.argumentOfPeriapsis = (double)UnityEngine.Random.Range(0.999f, 1.001f);
orbit.meanAnomalyAtEpoch = (double)UnityEngine.Random.Range(0.999f, 1.001f);

orbit.epoch = (double)UnityEngine.Random.Range(0.999f, 1.001f);
orbit.Init();
return orbit;
}

I tried making the LAN, epoch and incination the same as the nearOrbit but that doesn't help much. When I create random orbits till one is close I notice that the almost basically only the semiMajorAxis is close to the original orbit:

[LOG 21:42:33.989] LAN My: 115.483481610485 -- NewObj: 1.00026094913483

[LOG 21:42:33.990] Epoch My: 30235055.4039439 -- NewObj: 0.999513447284698

[LOG 21:42:33.990] Inclination My: 0 -- NewObj: -0.0787511840462685

Does anyone have an idea? Main idea is the new orbit should be within 10km of current orbit at a new height.

Link to comment
Share on other sites

Is it possible that the problem is that Orbit is rejecting values that are geometrically impossible because other fields you aren't setting are defaulting to values that contradict your settings? (i.e. imagine if you set the eccentricity to 1.5, but don't set the orbit's periapsis and apoapsis values.) Could it be that instead of altering periapsis and apopasis to match eccentricity, it's actually just rejecting the values you're giving it for being contradictory?)

Similar interdependencies between the values exist throughout the Orbit object's fields and properties, and it looks from the API as if it does not enforce the guarantee that you can only set the values in ways that are geometrically possible. Because KSP allows a lot more setting of public fields than it probably should (a lot of things it does with fields should really be wrapped in properties or method calls), it allows users of the API to create logically bogus sets of values.

Edited by Steven Mading
Link to comment
Share on other sites

Is it possible that the problem is that Orbit is rejecting values that are geometrically impossible because other fields you aren't setting are defaulting to values that contradict your settings? (i.e. imagine if you set the eccentricity to 1.5, but don't set the orbit's periapsis and apoapsis values.) Could it be that instead of altering periapsis and apopasis to match eccentricity, it's actually just rejecting the values you're giving it for being contradictory?)

Similar interdependencies between the values exist throughout the Orbit object's fields and properties, and it looks from the API as if it does not enforce the guarantee that you can only set the values in ways that are geometrically possible. Because KSP allows a lot more setting of public fields than it probably should (a lot of things it does with fields should really be wrapped in properties or method calls), it allows users of the API to create logically bogus sets of values.

The code above is actually the code KSP uses to create a random orbit around a body. I just added the "nearOrbit" part which I need to implement.

Link to comment
Share on other sites

I think this is what you want

deltaSMA is in meters

Keep in mind that an orbit can only be a fixed distance above another orbit if both are circular (eccentricity = 0).


public static Orbit CreateOrbitAroundAndNear(Orbit currentOrbit, double deltaSMA)
{

Orbit nearOrbit = new Orbit();
nearOrbit.referenceBody = currentOrbit.referenceBody;
nearOrbit.eccentricity = currentOrbit.eccentricity;

nearOrbit.semiMajorAxis = currentOrbit.semiMajorAxis + deltaSMA;
nearOrbit.inclination = currentOrbit.inclination;

nearOrbit.LAN = currentOrbit.LAN;

nearOrbit.argumentOfPeriapsis = currentOrbit.argumentOfPeriapsis;
nearOrbit.meanAnomalyAtEpoch = currentOrbit.meanAnomalyAtEpoch;

nearOrbit.epoch = currentOrbit.epoch;
nearOrbit.Init();
return nearOrbit;

}

Link to comment
Share on other sites

I think this is what you want

deltaSMA is in meters

Keep in mind that an orbit can only be a fixed distance above another orbit if both are circular (eccentricity = 0).


public static Orbit CreateOrbitAroundAndNear(Orbit currentOrbit, double deltaSMA)
{

Orbit nearOrbit = new Orbit();
nearOrbit.referenceBody = currentOrbit.referenceBody;
nearOrbit.eccentricity = currentOrbit.eccentricity;

nearOrbit.semiMajorAxis = currentOrbit.semiMajorAxis + deltaSMA;
nearOrbit.inclination = currentOrbit.inclination;

nearOrbit.LAN = currentOrbit.LAN;

nearOrbit.argumentOfPeriapsis = currentOrbit.argumentOfPeriapsis;
nearOrbit.meanAnomalyAtEpoch = currentOrbit.meanAnomalyAtEpoch;

nearOrbit.epoch = currentOrbit.epoch;
nearOrbit.Init();
return nearOrbit;

}

Thank you for the help, however you now create an orbit around the current vessels orbit. What is need is a fixed circular orbit of 100 kmwhere the new orbit is near the orbit of the reference vessel. So the argument of periapsis (i think) should be something which would make the orbit near the reference vessel.

To put in in context. I lift of with my vessel and at some point I'll get near 100km, I want to spawn vessels once you start approaching 100km in a circular orbit at this height near the ascending vessel..

Edited by m1nd0
Link to comment
Share on other sites

In NCI, I do fixed height orbits that way:

                    myVessel.orbitDriver.orbit = Orbit.CreateRandomOrbitAround(SelectedBody, minAlt, maxAlt);
myVessel.orbitDriver.orbit.LAN = OrbitLan;
myVessel.orbitDriver.orbit.argumentOfPeriapsis = OrbitW;

if you set min and max alt only 1 meter apart, it usually gives an orbit quite where you wanted - precision is about 30-100 meters from what I can tell..

HTH

Link to comment
Share on other sites

In NCI, I do fixed height orbits that way:

                    myVessel.orbitDriver.orbit = Orbit.CreateRandomOrbitAround(SelectedBody, minAlt, maxAlt);
myVessel.orbitDriver.orbit.LAN = OrbitLan;
myVessel.orbitDriver.orbit.argumentOfPeriapsis = OrbitW;

if you set min and max alt only 1 meter apart, it usually gives an orbit quite where you wanted - precision is about 30-100 meters from what I can tell..

HTH

That works as long as my own orbit is circular. As soon as my eccentricity becomes to far from 0 it stops working. I've had several attempts as most of them seem to work untill I change my orbit and my own eccentricity becomes larger then 0.05.

I even tried with only setting the argumentOfPeriapsis, but even then it the new orbit still doesn't make any sence.

This is with only argumentOfPeriapsis:

ee39c4af5c.jpg

This is with LAN and argumentOfperiapsis:

a2a4cb60b1.jpg

As you can see only setting argumentOfperiapsis comes closest but still is far from what it should be.

Annother one with LAN and argumentOfperiapsis:

fc1e0ecc9e.jpg

From this I can sort of tell the angle is calculated from the center of the orbit. So I'm guessing I will have to do some angle calculations and adjust the LAN based on the offset of the orbit center? This is just a bit to much for me to comprehend.

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