Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Orrery2 : MonoBehaviour
- {
- public Transform Center;
- public Transform Other;
- float x;
- float y;
- float z;
- float Begining = 1;
- float Elapsed;
- float dE = 0;
- // Update is called once per frame
- void FixedUpdate()
- {
- Elapsed = Begining++;
- PositionFromDate(100f, 0.8f, 1f, 2f, 2f, 2f);
- Debug.Log(Elapsed);
- Debug.Log("x:" + x + ", " + "y:" + y + ", " + "z:" + z);
- Other.transform.position = new Vector3(x, y, z);
- }
- void PositionFromDate(float a, float e, float i, float W, float w, float M)
- {
- M = M * Elapsed;
- //Newton's Method
- float E = M;
- while (Mathf.Abs(dE) < 1e-3)
- {
- dE = (E - e * Mathf.Sin(E) - M) / (1 - e * Mathf.Cos(E));
- E -= dE;
- Debug.Log("E:" + E + ", " + "e:" + e + ", " + "M:" + M + ", " + "dE:" + dE);
- }
- //Determine P and Q, 2d coordinate system in plane of orbit
- float P = a * (Mathf.Cos(E) - e);
- float Q = a * Mathf.Sin(E) * Mathf.Sqrt(Mathf.Abs(1 - Mathf.Pow(e, 2)));
- Debug.Log("Line 46 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- // rotate by argument of periapsis
- x = Mathf.Cos(w) * P - Mathf.Sin(w) * Q;
- y = Mathf.Sin(w) * P + Mathf.Cos(w) * Q;
- Debug.Log("Line 52 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- // rotate by inclination
- z = Mathf.Sin(i) * x;
- x = Mathf.Cos(i) * x;
- Debug.Log("Line 58 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- // rotate by longitude of ascending node
- float xTemp = x;
- x = Mathf.Cos(W) * xTemp - Mathf.Sin(W) * y;
- y = Mathf.Sin(W) * xTemp + Mathf.Cos(W) * y;
- Debug.Log("Line 65 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Orrery2 : MonoBehaviour
- {
- public Transform Center;
- public Transform Other;
- float x;
- float y;
- float z;
- float Begining = 1;
- float Elapsed;
- float dE = 0;
- //a: Semi-Major Axis
- //e: Eccentricity
- //i: Inclination
- //W: Longitude of the Ascending Node
- //w: Argument of Periapsis
- //M: Mean Anomaly
- //E: Eccentric Anomaly
- void FixedUpdate()
- {
- Elapsed = Begining++;
- PositionFromDate(1f, 0.8f, 10f, 2f, 2f, 2f);
- Debug.Log(Elapsed);
- Debug.Log("x:" + x + ", " + "y:" + y + ", " + "z:" + z);
- Other.transform.position = new Vector3(x, y, z);
- }
- void PositionFromDate(float a, float e, float i, float W, float w, float M)
- {
- a = a * Elapsed; //Semi-Major Axis
- e = e * Elapsed; //Eccentricity
- i = i * Elapsed; //Inclination
- W = W * Elapsed; //Longitude of the Ascending Node
- //Newton's Method
- float E = M;
- while (Mathf.Abs(dE) < 1e-3)
- {
- dE = (E - e * Mathf.Sin(E) - M) / (1 - e * Mathf.Cos(E));
- E -= dE;
- Debug.Log("E:" + E + ", " + "e:" + e + ", " + "M:" + M + ", " + "dE:" + dE);
- }
- //Determine P and Q, 2d coordinate system in plane of orbit
- float P = a * (Mathf.Cos(E) - e);
- float Q = a * Mathf.Sin(E) * Mathf.Sqrt(Mathf.Abs(1 - Mathf.Pow(e, 2)));
- Debug.Log("Line 46 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- // rotate by argument of periapsis
- x = Mathf.Cos(w) * P - Mathf.Sin(w) * Q;
- y = Mathf.Sin(w) * P + Mathf.Cos(w) * Q;
- Debug.Log("Line 52 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- // rotate by inclination
- z = Mathf.Sin(i) * x;
- x = Mathf.Cos(i) * x;
- Debug.Log("Line 58 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- // rotate by longitude of ascending node
- float xTemp = x;
- x = Mathf.Cos(W) * xTemp - Mathf.Sin(W) * y;
- y = Mathf.Sin(W) * xTemp + Mathf.Cos(W) * y;
- Debug.Log("Line 65 " + "a:" + a + ", " + "e:" + e + ", " + "i:" + i + "W:" + w + ", " + "w:" + w + ", " + "M:" + M + ", " + "E:" + E + ", " + "P:" + P + ", " + "Q:" + Q);
- }
- }
Add Comment
Please, Sign In to add comment