/// <summary> /// Updates the position and velocity of the body in its orbit based on /// the current anomaly. Reference plane is the ecliptic plane (J2000). /// </summary> void UpdatePositionAndVelocity() { // Heliocentric coordinates in its orbital plane r'. double rx = a * (Math.Cos(E) - ecc); double ry = a * Math.Sqrt(1 - ecc * ecc) * Math.Sin(E); // Heliocentric velocity in its orbital plane v'. double cosE = Math.Cos(E); double r = a * (1 - ecc * cosE); double k = Math.Sqrt(mu * a) / r; double vx = k * -Math.Sin(E); double vy = k * Math.Sqrt(1 - ecc * ecc) * cosE; double[,] T = OrbitUtils.GetTransformToEcliptic(i, Om, w); pos = OrbitUtils.ApplyTransform(rx, ry, T); vel = OrbitUtils.ApplyTransform(vx, vy, T); }
/// <summary> /// Gets the points on orbit ellipse. /// </summary> /// <param name="vertices">Reference array storing the vertices of the ellipse.</param> /// <param name="resolution">Number of vertices to draw ellipse.</param> public void GetEllipseFromTrueAnom(ref Vector3[] vertices, int resolution) { if (resolution < 2) { vertices = new Vector3[0]; return; } //if (ecc < 1 && ecc >= 0) if (vertices == null || vertices.Length != resolution) { vertices = new Vector3[resolution]; } // Resolution as the angular distance (nu) between each vertex. double nuResolution = OrbitUtils.TwoPI / resolution; double[,] T = OrbitUtils.GetTransformToEcliptic(i, Om, w); for (int i = 0; i < resolution; i++) { vertices[i] = GetVertexOfOrbitEllipse(a, ecc, i * nuResolution, T); } }