Python - Orbit of Satellite Around the Earth

by matt392 in Circuits > Software

60 Views, 1 Favorites, 0 Comments

Python - Orbit of Satellite Around the Earth

OrbitSatellite.jpg
meo.jpeg
OrbitEquationGraphic.png
print ("This program will calculate the orbit of a satellite around the Earth.")

import math

#  Formula for calculating the orbit of a satellite around the Earth:
#  SeparationDistrance = (AngularMomentumSquared/(OrbitingBodyMassSquared*EarthStandardGravitationalParameter))
#   * (1/(1+(EccentricityOfOrbit*CosineOfAngleOfTrueAnomaly)))
###########################################

# Enter the angular momentum, orbiting body mass, eccentricity of orbit, angle of true anomaly 
# Constants: EarthStandardGravitationalParameter: 398600.4418
#            Pi: math.pi

def SolveForOrbitOfSatellite():
    print ("Solving for the orbit of a satellite around the earth.")

    # Enter the angular momentum 
    AngularMomentum = float(input("Enter the angular momentum : ") )
    # Enter the orbiting body mass
    OrbitingBodyMass = float(input("Enter the orbiting body mass : ") )
    # Enter the eccentricity of orbit
    EccentricityOfOrbit = float(input("Enter the eccentricity of orbit : ") )
    # Enter the angle of true anomaly
    AngleOfTrueAnomaly = float(input("Enter the angle of true anomaly: ") )
    
    EarthStandardGravitationalParameter = 398600.4418
    print ("The Earth's Standard Gravitational Parameter is: ", EarthStandardGravitationalParameter)
    print("Pi is: ", math.pi)
        
    # Calculate left fraction first
    # Calculate top of left fraction
    AngularMomentumSquared = (AngularMomentum**2)
    print ("The angular momentum squared is: ", AngularMomentum)
    # Calculate bottom of the left fraction
    OrbitingBodyMassSquared = (OrbitingBodyMass**2)
    print ("The orbital body mass squared is: ", OrbitingBodyMassSquared)
    # Multiply by standard gravitational parameter
    BottomOfLeftFraction = (OrbitingBodyMassSquared*EarthStandardGravitationalParameter)
    print("The bottom of the left fraction is: ", BottomOfLeftFraction)
    # Get final result of left fraction
    LeftFraction = AngularMomentumSquared/BottomOfLeftFraction
    print("The left fraction is: ", LeftFraction)

    # Now calculate the right fraction
    # Get the cosine of the angle of true anomaly
    # First convert the angle to radians so that math.cos() can calculate it
    TrueAnomalyInRadians = math.radians(AngleOfTrueAnomaly)
    print ("The true anomaly in radians is: ", TrueAnomalyInRadians)
    CosineOfAngleOfTrueAnomaly = math.cos(TrueAnomalyInRadians)
    print ("The cosine of true anomaly is: ", CosineOfAngleOfTrueAnomaly)
    # Multiply cosine by eccentricity of orbit
    EccentricityTimesCosine = EccentricityOfOrbit*CosineOfAngleOfTrueAnomaly
    # Add one to get bottom fraction on right side
    BottomOfRightFraction = 1 + EccentricityTimesCosine
    print ("The bottom right fraction is: ", BottomOfRightFraction)
    # Get right fraction result
    RightFraction = 1/BottomOfRightFraction
    print("The right fraction is: ", RightFraction)

    # Finally multiply both left and right fractions together
    OrbitOfSatellite = LeftFraction * RightFraction
    print("The orbit of the satellite around the Earth is: ", OrbitOfSatellite)


ContinueCalculations = "y"

# Check to see if the user wants to continue to calculate the satellite orbit around the Earth
while (ContinueCalculations=="y"):
    SolveForOrbitOfSatellite()
    ContinueCalculations = input("Would like to do another calculation for a satellite orbit around the Earth? (y/n): ")

print("==================================")
print ("Thank you to www.fxsolver.com for assistance with this formula.")

Downloads