Search Unity

TLE / Calculating Satellite Orbits

Discussion in 'Scripting' started by Julien-Lynge, Apr 26, 2012.

  1. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    In a nutshell, I want simulate satellites orbiting around the earth based on the regular predictions that NORAD puts out, and was hopeful someone more mathematically inclined knew how to set up an equation of orbit.

    The technical stuff:
    I've been trying to take the TLE satellite path predictions put out by NORAD and use them to orbit satellites around an earth in Unity. I'm not looking for a full implementation of the SDP4 algorithm, and I don't even care about drag - I just want a very rough cut of an elliptical orbit.

    Any astrophysics buffs here who can tell me how to turn TLE (eccentricity, inclination,
    right ascension of the ascending node, etc.) into an orbital equation in 3 dimensions, assuming the center of the earth is at (0,0,0) and, say, +X is the right ascension / the poles are +/- Y?
     
  2. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    I just looked up the Keplerian Elements... wow, what a terrible choice of coordinate system! It's not too much maths, but it's far from simple, so you're probably best off just downloading something like this implementation of SDP4 and SGP4: http://www.zeptomoby.com/satellites/

    It looks like you can construct a Tle object based on your data, use that to construct an Orbit object, then query the position and velocity of the satellite at any time you specify by calling the GetPosition() method of the Orbit object. The position and velocity are returned in an Eci object, stored as in a custom 4-element vector type which you should be able to convert directly to a Unity Vector3 (ignoring the fourth element).

    Distances there are measured in kilometers, which is probably a sensible enough unit to use for this. Regardless of units, the numbers still get rather large. Using single-precision floats (which Unity does), with distances on the order of 10,000km from the centre of the earth, you can probably expect accuracy no better than 50cm. A chase cam attached to the satellite might not work very well unless you're careful with the maths.
     
  3. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    Thanks George!

    I poked around for a while trying to find a C# implementation, but all the articles I was finding were from 10 years ago and written in Fortran or C/C++ (which wouldn't be usable in the webplayer).

    I'll definitely take a look at this code. My biggest concern is speed - we would like to do this for around 15,000 satellites. Hopefully I can batch the calculations - calculate the position and velocity every X frames, and use simple Newtonian physics in between with slight trajectory corrections.
     
  4. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    Yes, I can't see any good parameterizations of elliptic orbits by time in the usual places, so presumably it's a hard problem, and that's probably why SDP and SGP exist. I don't know how complicated they are but you may be able to be more efficient if, as you say, you ignore drag and accept some inaccuracies. I'd first use the SDP/SGP code though as it's the simplest way to get a working model, then you can see how well it performs and decide whether you need something more efficient.

    Regarding calculating this more efficiently, the closest equation I can find to what you'd need, assuming no drag, is that you can go from elliptic anomaly E (squashed angle) to time via t = (e * sinh(E) - E) / sqrt(a * G * (m1+m2)) where e is the ellipse's eccentricity, a is the major radius, G is the gravitational constant, m1 and m2 are the masses of the two objects. This equation is hard to invert but you could still use an iterative algorithm to zero in on the value of E for a given t. Then it's easy to convert that to a position in space. So long as your time step is much smaller than your orbital period, you should be able to get a very accurate result from only one or two iterations, as although the velocities are not constant for the whole orbit, they may be almost constant within your timestep.