/// <summary>Compute dynamic properties that change over the anomaly</summary> /// <param name="M">The anomaly to evaluate properties at</param> public void ComputeDynamicProperties(double M) { eccentricAnomaly = Kepler.ComputeEccentricAnomaly(M, _eccentricity); trueAnomaly = Kepler.ComputeTrueAnomaly(eccentricAnomaly, _eccentricity); radius = Kepler.ComputeRadius(semiLatusRectum, _eccentricity, trueAnomaly); position = orientation * Kepler.ComputePosition(radius, trueAnomaly); velocity = orientation * Kepler.ComputeVelocity(_periapsis, radius, rate, eccentricAnomaly, trueAnomaly, _eccentricity); }
void OnDrawGizmosSelected() { //OnValidate should always be called before this, meaning appropriate values for properties are available //variables required Vector3[] path = new Vector3[51]; Vector3 periapsisV = orientation * Vector3.right * (float)_periapsis; Vector3 positionV = orientation * Kepler.ComputePosition(Kepler.ComputeRadius(semiLatusRectum, _eccentricity, trueAnomaly), trueAnomaly); //elliptical and circular //build list of vectors for path double step, lower, upper; double r; lower = Kepler.ComputeTrueAnomaly(Kepler.ComputeEccentricAnomaly(_limits.x * Deg2Rad, _eccentricity), _eccentricity); upper = Kepler.ComputeTrueAnomaly(Kepler.ComputeEccentricAnomaly(_limits.y * Deg2Rad, _eccentricity), _eccentricity); step = (upper - lower) / 50; for (int i = 0; i <= 50; i++) { r = Kepler.ComputeRadius(semiLatusRectum, _eccentricity, lower + i * step); path[i] = Kepler.ComputePosition(r, lower + i * step); } //Set the gizmos to draw in parent space Gizmos.matrix = (transform.parent)? transform.parent.localToWorldMatrix : Matrix4x4.identity; //draw the path of the orbit Gizmos.color = Color.cyan; for (int i = 0; i < 50; i++) { Gizmos.DrawLine(orientation * path[i], orientation * path[i + 1]); } //draw periapsis vector Gizmos.DrawLine(Vector3.zero, periapsisV); //draw position vector Gizmos.color = Color.blue; Gizmos.DrawLine(Vector3.zero, positionV); //draw velocity vector Gizmos.color = Color.magenta; Gizmos.DrawLine(positionV, positionV + velocity); }
void OnEnable() { if (orbit == null) { line.SetVertexCount(0); } else { double step, lower, upper, r; Matrix4x4 matrix = (transform.parent)? transform.parent.localToWorldMatrix : Matrix4x4.identity; line.SetVertexCount(segments + 1); upper = Kepler.ComputeTrueAnomaly(Kepler.ComputeEccentricAnomaly(orbit.limits.x * Deg2Rad, orbit.eccentricity), orbit.eccentricity); lower = Kepler.ComputeTrueAnomaly(Kepler.ComputeEccentricAnomaly(orbit.limits.y * Deg2Rad, orbit.eccentricity), orbit.eccentricity); step = (upper - lower) / segments; for (int i = 0; i < segments + 1; i++) { r = Kepler.ComputeRadius(orbit.semiLatusRectum, orbit.eccentricity, lower + step * i); line.SetPosition(i, matrix.MultiplyPoint(orbit.orientation * Kepler.ComputePosition(r, lower + step * i))); } } }