SHARE
TWEET

Untitled

a guest May 13th, 2017 188 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Orbital parameters
  2.     public double[] semimajorAxis = new double[2]; //[au, au/century]
  3.     public double[] eccentricity = new double[2]; //[ , /century]
  4.     public double[] inclination = new double[2]; //inclination [degrees, degrees/century]
  5.     public double[] meanLongitude = new double[2]; //inclination [degrees, degrees/century]
  6.     public double[] longitudeOfPerihelion = new double[2]; //inclination [degrees, degrees/century]
  7.     public double[] longitudeOfTheAscendingNode = new double[2]; //inclination [degrees, degrees/century]
  8.  
  9. void ComputePositionAtDate(){
  10.         double tMillisFromJ2000 = DateTime.Now.ToUniversalTime().Subtract(new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
  11.         double tCenturiesFromJ2000 = tMillisFromJ2000 / (1000 * 60 * 60 * 24 * 365.25 * 100);
  12.         double a = semimajorAxis [0] + semimajorAxis [1] * tCenturiesFromJ2000;
  13.         double e = eccentricity [0] + eccentricity [1] * tCenturiesFromJ2000;
  14.         double i = inclination [0] + inclination [1] * tCenturiesFromJ2000;
  15.         double L = Math.IEEERemainder(Math.IEEERemainder(meanLongitude[1] * tCenturiesFromJ2000, 360) + meanLongitude[0], 360);
  16.  
  17.         Debug.Log (this.name + ": " + L);
  18.  
  19.         double p = longitudeOfPerihelion [0] + longitudeOfPerihelion [1] * tCenturiesFromJ2000;
  20.         double W = longitudeOfTheAscendingNode [0] + longitudeOfTheAscendingNode [1] * tCenturiesFromJ2000;
  21.  
  22.         double M = L - p;
  23.         double w = p - W;
  24.  
  25.         double E = M;
  26.         while (true) {
  27.             double dE = (E - e * Mathd.Sin (E) - M) / (1 - e * Mathd.Cos (E));
  28.             E -= dE;
  29.             if (Mathd.Abs (dE) < 1e-6)
  30.                 break;
  31.         }
  32.  
  33.         double P = a * (Mathd.Cos (E) - e);
  34.         double Q = a * Mathd.Sin (E) * Math.Sqrt (1 - Mathd.Pow (e, 2d));
  35.  
  36.         // rotate by argument of periapsis
  37.         double x = Mathd.Cos(w) * P - Mathd.Sin(w) * Q;
  38.         double y = Mathd.Sin (w) * P + Mathd.Cos (w) * Q;
  39.         // rotate by inclination
  40.         double z = Mathd.Sin(i) * x;
  41.         x = Mathd.Cos (i * x);
  42.         // rotate by longitude of ascending node
  43.         double xTemp = x;
  44.         x = Mathd.Cos (W) * xTemp - Mathd.Sin (W) * y;
  45.         y = Mathd.Sin (W) * xTemp + Mathd.Cos (W) * y;
  46.  
  47.         position = new Vector3d (x * 149597870700d, z * 149597870700d, y * 149597870700d);
  48.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top