Plotting a Hyperbolic Trajectory

HarvesteR

Member
Joined
Apr 22, 2008
Messages
386
Reaction score
15
Points
18
Hello again!

I'm faced with a problem that hopefully someone will be able to help me with.

I'm writing an orbital analysis system here, to compute the keplerian elements of objects in orbit from their state vectors. Most of it is working already, and the system can analyze any object in orbit in relation to any arbitrary reference body, then draw out the orbital path.

My problem is this: The orbit drawing uses a different approach for hyperbolic orbits. Instead of finding the eccentric anomaly from the mean, then the true anomaly and radius, it uses the true anomaly and the Orbit Equation to find the radius.

So far so good. The system is perfectly able to draw up the hyperbola, and it matches the actual trajectory fine.

My problem is knowing when to start and when to stop drawing.

The drawing routine (just a test for now), draws the trajectory based on an arbitraty true anomaly value I give it. More precisely, I'm iterating from -180° to 180°, and drawing a line between the increments (0.5° currently).

To make things easier to understand, here's the code I'm talking about:

Code:
float drawResolution = 0.5f;
public void DrawOrbit()
{
    // some irrelevant bits ommited here

    // draw the trajectory by finding positions at arbitrary angles
    for (float i = -Mathf.PI; i < Mathf.PI; i+= drawResolution * Mathf.Deg2Rad)
    {
        Debug.DrawLine(getRelativePositionFromTrueAnomaly(i), getRelativePositionFromTrueAnomaly(i + drawResolution * Mathf.Deg2Rad), Color.green);
    }
}

// This method returns a Unity-friendly position from the given True Anomaly angle
public Vector3 getRelativePositionFromTrueAnomaly(float tA)
{
    // use the Orbit Equation to get the distance from the focus
    float R = semiLatusRectum * (1f / (1f + eccentricity * Mathf.Cos(tA)));

    // Then, rotate a vector to match the orbit, and stretch it by the distance
    Vector3 ascNd = Quaternion.AngleAxis(LAN, Vector3.forward) * Vector3.right;
    Vector3 p = Quaternion.AngleAxis(argumentOfPeriapsis, h) * ascNd;
    p = (Quaternion.AngleAxis(tA * Mathf.Rad2Deg, h) * p) * R;

    return new Vector3(p.x, p.z, p.y); //flip the Y and Z axes, since Unity works in Y-up
}

But what happens is that not only the trajectory gets drawn, the other side of the hyperbola gets drawn too... which is logical, since I'm just going around the whole thing...

But, how can I calculate the max and min angles (the start and end of that 'for' loop there) to draw between? I've tried going from -90° to 90°, and the line comes up short.

I also noticed that the starting and ending angles vary with the trajectory eccentricity... But I can't seem to figure out the relation, and wikipedia isn't being very helpful on this.

I hope my explanation of the problem is clear enough... If you need any more information, just ask.

As always, thanks in advance! :thumbup:

Cheers

---------- Post added at 02:24 PM ---------- Previous post was at 02:04 PM ----------

I just had to add this. It really made my day :rofl:

(open each link in a separate tab)

http://www.haverford.edu/physics/songs/rHyperbolic.mp3

http://www.haverford.edu/physics/songs/rhyperboliclyrics.htm

:thumbup:

Cheers

---------- Post added at 02:40 PM ---------- Previous post was at 02:24 PM ----------

Just to add one more thing...

I've found that I can get very near to the trajectory's asymptote angles by iterating from this:

-2f * Mathf.Pow(Mathf.Cos(1f / eccentricity), -1f)

to this:

2f * Mathf.Pow(Mathf.Cos(1f / eccentricity), -1f)

But there's still quite a bit of extra lines being drawn there... But with this expression, at least the amount of surplus trajectory doesn't vary with eccentricity, which means I must be making some progress I think.

Does anyone have a thought about this?

Cheers
 
Last edited:

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
well, it really would help if you could show us a picture of what exactly it's doing wrong....

but hmm, did you try iterating from zero up to 2*Pi instead of from neg to pos? :hmm:



kinda hard to guess what goes where if we can't see precisely what you mean by "the other side" of the hyperbola....

:thumbup:
 

HarvesteR

Member
Joined
Apr 22, 2008
Messages
386
Reaction score
15
Points
18
I think I've found it. Turns out wikipedia does have the answer :)

The range of the true anomaly for a hyperbolic orbit is:

-Mathf.Acos(-(1f / eccentricity)) < theta < Mathf.Acos(-(1f / eccentricity))


That puts the drawing limits precisely at the asymptotes, where r = infinity. Too precisely, I must say, sometimes it overdraws a bit (in a most displeasing flickering manner), but I think I can add a safety cap now :)

Cheers
 
Top