Assets/Scripts/OrbitUpdater.cs
/// <summary>
/// Calculate position in orbit relative to orbit origin
/// </summary>
/// <param name="trueAnomaly">True anomaly, radians</param>
Calculate position in orbit relative to orbit origin
Calculate position in orbit relative to orbit origin
public Vector3 CalculatePosition(float trueAnomaly)
    {
        float radius = CurrentSemiMajorAxis * (1 - CurrentEccentricity * CurrentEccentricity) / (1 + CurrentEccentricity * Mathf.Cos(trueAnomaly));
        return new Vector3(
            radius * (Mathf.Cos(RightAscensionOfAscendingNode) * Mathf.Cos(trueAnomaly + ArgumentOfPerigee) - Mathf.Sin(RightAscensionOfAscendingNode) * Mathf.Sin(trueAnomaly + ArgumentOfPerigee) * Mathf.Cos(CurrentInclination)),
            radius * (Mathf.Sin(trueAnomaly + ArgumentOfPerigee) * Mathf.Sin(CurrentInclination)),
            -radius * (Mathf.Sin(RightAscensionOfAscendingNode) * Mathf.Cos(trueAnomaly + ArgumentOfPerigee) + Mathf.Cos(RightAscensionOfAscendingNode) * Mathf.Sin(trueAnomaly + ArgumentOfPerigee) * Mathf.Cos(CurrentInclination)));
    }
public Vector3 CalculatePosition ( float trueAnomaly ) { float radius = CurrentSemiMajorAxis * ( 1 - CurrentEccentricity * CurrentEccentricity ) / ( 1 + CurrentEccentricity * Mathf . Cos ( trueAnomaly ) ) ; return new Vector3 ( radius * ( Mathf . Cos ( RightAscensionOfAscendingNode ) * Mathf . Cos ( trueAnomaly + ArgumentOfPerigee ) - Mathf . Sin ( RightAscensionOfAscendingNode ) * Mathf . Sin ( trueAnomaly + ArgumentOfPerigee ) * Mathf . Cos ( CurrentInclination ) ) , radius * ( Mathf . Sin ( trueAnomaly + ArgumentOfPerigee ) * Mathf . Sin ( CurrentInclination ) ) , - radius * ( Mathf . Sin ( RightAscensionOfAscendingNode ) * Mathf . Cos ( trueAnomaly + ArgumentOfPerigee ) + Mathf . Cos ( RightAscensionOfAscendingNode ) * Mathf . Sin ( trueAnomaly + ArgumentOfPerigee ) * Mathf . Cos ( CurrentInclination ) ) ) ; }
Calculate position in orbit relative to orbit origin
Calculate position in orbit relative to orbit origin
// Compute radius from orbit origin // Calculate position relative to orbit origin // XZ-plane is ecliptic, Y towards celestial north pole
trueAnomaly
float
True anomaly, radians
True anomaly radians