Pages

Wednesday, March 28, 2012

Calculating orbital velocity with Python

Earlier we calculated escape velocity for a rocket using Python, and today, we are going to look at calculating orbital velocity using Python. For a background on some of the terms I use, you may want to refer to the above linked article.

Orbital velocity is what the Space
Shuttle needs to reach to get to orbit.
Orbital velocity is very similar to escape velocity, except that it is instead what is necessary to achieve orbit, rather than totally escape a planet's gravity well. That is, if we're trying to get into orbit from the ground (like the Space Shuttle), we calculate orbital velocity. If we're trying to get to Mars (i.e. escape Earth's gravity well), we calculate escape velocity (as well as Mars' escape velocity in that case).

The formula for orbital velocity is as follows:

Vo ≈ sqrt[ GM / r ]

where

Vo = Orbital velocity (m/s)
G = Gravitational constant
M = Mass of planet (kg)
r = Distance from planet's center of gravity the rocket is launching at (m)

We can easily write a Python function to solve for this. In fact, it's almost identical to the one we wrote for calculating escape velocity:

from decimal import *

_GRAVITATIONAL_CONSTANT = Decimal('6.67384E-11')

def orbital_velocity(mass, radius):
    '''Calculates the delta-V orbital velocity.

    Returns delta-V in meters per second for the orbital
    velocity for a given object given its mass in kilograms
    and its radius in meters.'''

    if mass == Decimal('0') or radius == Decimal('0'):
        # User gave a mass or radius which is unrealistic,
        # abort.
        return None
    
    result = Decimal((_GRAVITATIONAL_CONSTANT * mass) / radius)
    result = result.sqrt()

    return result

Let's run this using our figures for Earth (mean radius of 6,371 km, mass of 5.9736E24 kg), assuming the above code is in sci.py:

>>> from decimal import *
>>> import sci
>>> sci.orbital_velocity(Decimal('5.9736E24'), Decimal('6371000'))
Decimal('7910.467706232366495042659538')

So, 7.9 km/s is approximately the orbital velocity according to our function. And, if we check the Wikipedia article for orbital velocity, it mentions that for low Earth orbit, the orbital velocity ranges from 6.9 km/s to 7.8 km/s! That's what I call close enough for government work.

1 comment:

  1. This article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article. velocity calculator

    ReplyDelete