Skip to content

Blue3125/OrbiPy

Repository files navigation

OrbiPy

A library to model and predict parameters of orbits.

Tutorial

This tutorial will cover the basics of how to implement the OrbiPy library effectively.

Number Crunching

Given a set variables we can calculate the unknown values using one of our functions. We will demonstrate using the calculate_gravitational_pull function to calculate the radius (from centres of bodies) of the Moon's orbit around the Earth.

$F = 1.980 \times 10 ^ {20} \text{N}$

$M_1 = 5.972 \times 10 ^ {24} \text{kg}$

$M_2 = 7.348 \times 10 ^ {22} \text{kg}$

To do this, we use the following code:

import orbipy as orb
import sympy as sym

r = sym.Symbol("r")

radius = orb.calculate_gravitational_pull(unknown=r, F=198_000_000_000_000_000_000, M_1=5_972_000_000_000_000_000_000_000, M_2=73_480_000_000_000_000_000_000, r=r)

radius

This will give:

384604835.388798

As the solution of r

Plot An Orbit

import orbipy as orb

orb.plot_orbit_n(orbits=[orb.LineInfo(a=0, b=1, theta=0, colour="blue", label="Earth"),
             orb.LineInfo(a=0.0549, b=384000000, c=1, theta=0, colour="grey",
                label="Moon")])

The result should be a plot of the moon going around the earth (blue dot in centre, grey circle slightly off centre).

See Here

Animate An Orbit

import orbipy as orb

orb.animate_orbit_n(orbits=[orb.OrbitInfo(a=0, b=0, theta=0, 
                line_colour="blue", label="Earth", size=10.98, point_colour="b"),
                orb.OrbitInfo(a=0.0549, b=384000000, c=1, theta=0, 
                line_colour="grey", label="Moon", size=3, point_colour="k")])

The result should be an animation of a grey line (and black dot) completing a roughly circular orbit around a blue dot.

See Here

How To

How To Use The Number Crunching Functions

How to use the funtion calculate_gravitational_pull()

How to compute F

Given:

  • $M_1=10000000000$
  • $M_2=200000000$
  • $r=10$

F is:

import orbipy as orb

Force = orb.calculate_gravitational_pull(unknown=F, F=F, M_1=10000000000, M_2=200000000, r=10)
Force

This gives:

{1334860.00000000}
How to compute M_1

Given:

  • $F=1334860$
  • $M_2=200000000$
  • $r=10$

M_1 is:

import orbipy as orb

Mass = orb.calculate_gravitational_pull(unknown=M_1, F=1334860, M_1=M_1, M_2=200000000, r=10)
Mass

This gives:

{10000000000.0000}
How to compute M_2

Given:

  • $F=1334860$
  • $M_1=10000000000$
  • $r=10$

M_2 is:

import orbipy as orb

Mass = orb.calculate_gravitational_pull(unknown=M_2, F=1334860, M_1=10000000000, M_2=M_2, r=10)
Mass

This gives:

{200000000.000000}
How to compute r

Given:

  • $F=1334860$
  • $M_1=10000000000$
  • $M_2=200000000$

r is:

import orbipy as orb

radius = orb.calculate_gravitational_pull(unknown=r, F=1334860, M_1=10000000000, M_2=200000000, r=r)
radius

This gives:

{10.0000000000000}

How to use the funtion calculate_kinetic_energy()

How to compute KE

Given:

  • $m=5$
  • $v=10$

KE is:

import orbipy as orb

Ke = orb.calculate_kinetic_energy(unknown=KE, KE=KE, m=5, v=10)
Ke

This gives:

{250.0}
How to compute m

Given:

  • $KE=250$
  • $v=10$

Mass is:

import orbipy as orb

Mass = orb.calculate_kinetic_energy(unknown=m, KE=250, m=m, v=10)
Mass

This gives:

{5.0}
How to compute v

Given:

  • $Ke=250$
  • $m=5$

v is:

import orbipy as orb

Velocity = orb.calculate_gravitational_pull(unknown=M_2, F=1334860, M_1=10000000000, M_2=M_2, r=10)
Velocity

This gives:

{10.0}

How to use the funtion calculate_gravitational_potential_energy()

How to compute GPE

Given:

  • $m=100$
  • $g=10$
  • $r=12$

GPE is:

import orbipy as orb

GPE = orb.calculate_gravitational_potential_energy(unknown=GPE, GPE=GPE, m=100, g=10, r=12)
GPE

This gives:

{12000}
How to compute m

Given:

  • $GPE=12000$
  • $g=10$
  • $r=12$

m is:

import orbipy as orb

mass = orb.calculate_gravitational_potential_energy(unknown=m, GPE=12000, m=m, g=10, r=12)
mass

This gives:

{100}
How to compute g

Given:

  • $GPE=12000$
  • $m=100$
  • $r=12$

g is:

import orbipy as orb

g = orb.calculate_gravitational_potential_energy(unknown=g, GPE=12000, m=100, g=g, r=12)
g

This gives:

{10}
How to compute r

Given:

  • $GPE=12000$
  • $m=100$
  • $g=10$

GPE is:

import orbipy as orb

radius = orb.calculate_gravitational_potential_energy(unknown=r, GPE=12000, m=100, g=10, r=r)
radius

This gives:

{12}

How to use the funtion calculate_gravitational_acceleration()

How to compute g

Given:

  • $M=100000000$
  • $r=10$

g is:

import orbipy as orb

g = orb.calculate_gravitational_acceleration(unknown=g, g=g, M=10000000000000, r=10)
g

This gives:

{6.6743}
How to compute M

Given:

  • $g=6.6743$
  • $r=10$

M is:

import orbipy as orb

mass = orb.calculate_gravitational_acceleration(unknown=M, g=6.6743, M=M, r=10)
mass

This gives:

{10000000000000.0}
How to compute r

Given:

  • $g=6.6743$
  • $M=10000000000000$

r is:

import orbipy as orb

radius = orb.calculate_gravitational_acceleration(unknown=r, g=6.6743, M=10000000000000, r=r)
radius

This gives:

{10.0}

How to use the funtion calculate_masses_angular_position()

How to compute theta

Given:

  • $M=100000000000$
  • $r=2$
  • $T=2$

theta is:

import orbipy as orb

theta = orb.calculate_masses_angular_position(unknown=theta, M=100000000000, r=2, T=2, theta=theta)
theta

This gives:

{1.82678679653648}
How to compute M

Given:

  • $theta=1.82678679653648$
  • $r=2$
  • $-T=2$

M is:

import orbipy as orb

mass = orb.calculate_masses_angular_position(unknown=M, M=M, r=2, T=2, theta=1.82678679653648)
mass

This gives:

{100000000000.0}
How to compute r

Given:

  • $theta=1.82678679653648$
  • $M=100000000000$
  • $T=2$

r is:

import orbipy as orb

radius = orb.calculate_masses_angular_position(unknown=r, M=100000000000, r=r, T=2, theta=1.82678679653648)
radius

This gives:

{2.0}
How to compute T

Given:

  • $theta=1.82678679653648$
  • $M=100000000000$
  • $r=2$

T is:

import orbipy as orb

T = orb.calculate_masses_angular_position(unknown=r, M=100000000000, r=2, T=T, theta=1.82678679653648)
T

This gives:

{2.0}

How to use the funtion calculate_linear_velocity()

How to compute v

Given:

  • $r=2$
  • $t=3$
  • $theta=3.14$

v is:

import orbipy as orb


velocity = orb.calculate_linear_velocity(unknown=v, v=v, r=2, t=3, theta = 3.14)
velocity

This gives:

[2.09333333333333]
How to compute r

Given:

  • $v=2.09333333333333$
  • $t=3$
  • $theta=3.14$

r is:

import orbipy as orb


radius = orb.calculate_linear_velocity(unknown=r, v=2.09333333333333, r=r, t=3, theta = 3.14)
radius

This gives:

[2.00000000000000]
How to compute t

Given:

  • $v=2.09333333333333$
  • $r=2$
  • $theta=3.14$

t is:

import orbipy as orb


time = orb.calculate_linear_velocity(unknown=r, v=2.09333333333333, r=2, t=t, theta = 3.14)
time

This gives:

[3.00000000000000]
How to compute theta

Given:

  • $v=2.09333333333333$
  • $r=2$
  • $t=3$

theta is:

import orbipy as orb


theta = orb.calculate_linear_velocity(unknown=r, v=2.09333333333333, r=2, t=3, theta = theta)
theta

This gives:

[3.14000000000000]

How to use the funtion calculate_time_period_of_orbit()

How to compute T

Given:

  • $M=10000$
  • $r=20$

T is:

import orbipy as orb

T = orb.calculate_time_period_of_orbit(unknown=T, T=T, M=10000, r=20)
T

This gives:

[687894.758062878]
How to compute M

Given:

  • $T=687894.758062878$
  • $r=20$

M is:

import orbipy as orb

mass = orb.calculate_time_period_of_orbit(unknown=M, T=687894.758062878, M=M, r=20)
mass

This gives:

[10000.0000000000]
How to compute r

Given:

  • $T=687894.758062878$
  • $M=10000$

r is:

import orbipy as orb

radius = orb.calculate_time_period_of_orbit(unknown=r, T=687894.758062878, M=10000, r=r)
radius

This gives:

[20.0000000000000]

How to use the funtion calculate_electrostatic_force()

How to compute F

Given:

  • $Q=10000000000$
  • $q=200000000$
  • $r=10$

F is:

import orbipy as orb

Force = orb.calculate_electrostatic_force(unknown=F, F=F, Q=10000000000, q=200000000, r=10)
Force

This gives:

[1334860.00000000]
How to compute Q

Given:

  • $F=1334860$
  • $q=200000000$
  • $r=10$

Q is:

import orbipy as orb

charge = orb.calculate_electrostatic_force(unknown=Q, F=1334860, Q=Q, q=200000000, r=10)
charge

This gives:

[10000000000.0000]
How to compute q

Given:

  • $F=1334860$
  • $Q=10000000000$
  • $r=10$

q is:

import orbipy as orb

charge = orb.calculate_electrostatic_force(unknown=q, F=1334860, Q=10000000000, q=q, r=10)
charge

This gives:

[200000000.000000]
How to compute r

Given:

  • $F=1334860$
  • $Q=10000000000$
  • $q=200000000$

r is:

import orbipy as orb

radius = orb.calculate_electrostatic_force(unknown=r, F=1334860, Q=10000000000, q=200000000, r=r)
radius

This gives:

[10.0000000000000]

calculate_charges_angular_position(unknown: sym.Symbol, k: int|float = k, Q: int|float = Q, r: int|float = r, T: int|float = T, theta: int|float = theta)

How to use the funtion calculate_charges_angular_position()

How to compute theta

Given:

  • $Q=100000000000$
  • $r=2$
  • $T=93.6687653240416$

theta is:

import orbipy as orb

theta = orb.calculate_charges_angular_position(unknown=theta, Q=1, r=20000, T=93.6687653240416, theta=theta)
theta

This gives:

{93.6687653240416}
How to compute Q

Given:

  • $r=2$
  • $T=93.6687653240416$
  • $theta=3.14$

Q is:

import orbipy as orb

charge = orb.calculate_charges_angular_position(unknown=Q, Q=Q, r=20000, T=93.6687653240416, theta=3.14)
charge

This gives:

{1.00000000000000}
How to compute r

Given:

  • $Q=100000000000$
  • $T=93.6687653240416$
  • $theta=3.14$

r is:

import orbipy as orb

radius = orb.calculate_charges_angular_position(unknown=r, Q=1, r=r, T=93.6687653240416, theta=3.14)
radius

This gives:

{20000.0000000000}
How to compute T

Given:

  • $Q=100000000000$
  • $r=2$
  • $theta=3.14$

T is:

import orbipy as orb

T = orb.calculate_charges_angular_position(unknown=T, Q=1, r=20000, T=T, theta=3.14)
T

This gives:

{93.6687653240416}

How to use the funtion parralax()

Given:

  • $theta=0.0001$

d is:

import orbipy as orb

distance = orb.parralax(theta=0.0001)
distance

This gives:

{10000.0}

How to use the funtion redshift_distance()

Given:

  • $z=2.14$

d is:

import orbipy as orb

distance = orb.redshift_distance(z=2.14)
distance

This gives:

{9197.70773638968}

How to use the funtion calculate_velocity_from_H()

Given:

  • $d=100000$

v is:

import orbipy as orb

velocity = orb.calculate_velocity_from_H(d=100000)
velocity

This gives:

{1.43266475644699}

How to use the funtion redshift_z()

Given:

  • $lamda_o=0.000000007$
  • $lamda_r=0.000000004$

z is:

import orbipy as orb

z = orb.redshift_z(lamda_o=0.000000007 ,lamda_r=0.000000004):
z

This gives:

{0.75}

How to use the funtion calculate_eccentricity()

Given:

  • $c=10000000000$
  • $a=20000000000$

e is:

import orbipy as orb

eccentricity = orb.calculate_eccentricity(c=10000000000,a=20000000000)
eccentricity

This gives:

0.5

How to use the funtion orbital_parameters()

Given:

  • $w=10$
  • $e=0.1$
  • $a=9000000$
  • $t=0$
  • $M=20$
  • $M=10$
  • $theta=3.14$
import orbipy as orb

orb.orbital_parameters(w=10,e=0.1,a=9000000,t=0,M=20,m=10,theta=3.14)

This gives:

('GPE = -1.3483436243508612e-15',
 'Ke = 6.067547354619726e-0.8',
 'v= 1.015940590453206e-08'
 'r= 9899998.60490049',
 'x = -9899986.049004901',
 'y = 15767.261651310297',
 'v= 0.1',
 'v= 0.01/distance**3',
 'v=0.00912544053345259*(distance**(-6))**0.333333333333333',
 'v=9899998.60490049',
 'energy= -7.415888888888888e-16')

How to use the funtion plot_orbital_parameters()

Given:

  • $omega=10$
  • $e=0.1$
  • $a=9000000$
  • $M=20$
  • $M=10$
  • $theta=3.14$
import orbipy as orb

orb.plot_orbital_parameters(omega=10,e=0.1,a=9000000,M=20,m=10,theta= 3.14)

This gives:

('Ke_max = 9.06386389238886e-16',
 'Ke_min = 6.067545529423612e-16',
 'GPE_max = -1.34834344183125e-15',
 'GPE_min = -1.6479752781277748e-15',
 'r_max = 9899999.945021888',
 'r_min = 8100000.149981027',
 'v_max = 1.346392505355616e-08'
 'v_min = 1.1015938933584927e-08'
 'T = 0.1'
 'e = -7.415888888888887e-16')

and an image of the graph plotting the functions;radius, velocity, Ke, GPE, energy against time

How To Use The Plotting/Animation Functions

This section includes two versatile functions. These functions can model a large varity of orbits and orbit combinations, however they do each have specific draw backs that are important to be aware of.

NOTE: I have used the same examples for each function, to demonstrate how they relate to each other.

plot_orbit_n

This function is used to produce a static diagram of orbital paths.

The following code is an example of how the function could be used to model a small selection of saturn's moons.

import orbipy as orb

orb.plot_orbit_n(orbits=[orb.LineInfo(a=0.000, b=1, theta=0, colour="brown", label="Saturn"),
                     orb.LineInfo(a=0.000, b=116914000, c=154, theta=0, colour="red", label="S/2009 S_1", orbit_previous=False),
                     orb.LineInfo(a=0.000, b=133584000, c=126, theta=0, colour="orange", label="Pan", orbit_previous=False),
                     orb.LineInfo(a=0.000, b=136500000, c=122, theta=0, colour="yellow", label="Daphnis", orbit_previous=False),
                     orb.LineInfo(a=0.001, b=137700000, c=121, theta=0, colour="green", label="Atlas", orbit_previous=False),
                     orb.LineInfo(a=0.002, b=139400000, c=119, theta=0, colour="blue", label="Prometheus", orbit_previous=False),
                     orb.LineInfo(a=0.004, b=141700000, c=105, theta=0, colour="purple", label="Pandora", orbit_previous=False)
                     ])

Let's break this down:

We first need to know what we are looking for.

In this example, I used the data from https://en.wikipedia.org/wiki/Moons_of_Saturn#List

a

a is the eccentricity of the orbit. You can calculate this using the calculate_eccentricity() function that is included in our library. You can also calculate it by hand using $\text{eccentricity} = \frac{\text{semi-minor axis}}{sem-major axis}$. Sometimes you can find the eccentricity online as well.

b

b is the semi-major axis. This is easiest to find online.

c

c is the angular velocity of the object. This is hard to find explicitely. Use the formula $\text{angular velocity} = \frac{2π}{\text{time period(s)}}$

NOTE: c being very small sometimes leads to issues, however usually quite they are easy to fix. If a plot comes out as a series of straight lines, try multiplying all the c values by a constant.

theta

theta is simply the initial angular position of the object. while using plot_orbit_n alone, this variable has little effect.

colour

colour is the colour you want the orbit of this object to be.

label

label is the name of the body (used in legend/key).

orbit_previous

orbit_previous is a boolean (True/False). It is True by default. When True, the current object will be orbitting around the previous objects. When False, the current object will orbit the centre.

Currently, if orbit_previous is True, it will orbit all previous orbits. This will usually not be a problem, however if you are modelling, for instance, Murcury, Venus, Earth going around the sun, and the moon going around the Earth, the Earth must before both Murcury and Venus, with the moon directly afterwards.

Bringing it back

Looking back to the code above, hopefully you can see where all my values came from.

See Here

I will now show another example that has stacking orbits (orbit_previous = True). Disclaimer: The following example is going to look odd, it is random numbers to demonstate how much variety orbits can have.

import orbipy as orb

orb.plot_orbit_n(orbits=[orb.LineInfo(a=0.430, b=100, theta=0, colour="pink", label="Donkey"),
                     orb.LineInfo(a=0.500, b=10, c=4, theta=5, colour="purple", label="Penguin", orbit_previous=True),
                     orb.LineInfo(a=0.030, b=50, c=0.015, theta=0, colour="blue", label="Dolphin", orbit_previous=True),
                     orb.LineInfo(a=0.009, b=25, c=52, theta=65, colour="orange", label="Quail", orbit_previous=True),
                     orb.LineInfo(a=0.132, b=15, c=9.08, theta=73, colour="red", label="Field Mouse", orbit_previous=True),
                     orb.LineInfo(a=0.080, b=250, c=20, theta=221, colour="green", label="Guinea Pig", orbit_previous=True),
                     orb.LineInfo(a=0.034, b=5, c=21, theta=9, colour="black", label="Elephant", orbit_previous=True)
                     ])

See Here

animate_orbit_n

This function can be used to produce an animation of orbital paths

The following code is an example of how the function could be used to model a small selection of saturn's moons.

import orbipy as orb

orb.animate_orbit_n(interval=50, orbits=[orb.OrbitInfo(a=0.000, b=0, theta=0, line_colour="brown", point_colour="y",
                                  label="Saturn", size=10, orbit_previous=False),
                        orb.OrbitInfo(a=0.000, b=116914000, c=154, theta=0, line_colour="red", point_colour="r",
                                  label="S/2009 S_1", size=1, orbit_previous=False),
                        orb.OrbitInfo(a=0.000, b=133584000, c=126, theta=0, line_colour="orange", point_colour="c",
                                  label="Pan", size=1, orbit_previous=False),
                        orb.OrbitInfo(a=0.000, b=136500000, c=122, theta=0, line_colour="yellow", point_colour="k",
                                  label="Daphnis", size=1, orbit_previous=False),
                        orb.OrbitInfo(a=0.000, b=137700000, c=121, theta=0, line_colour="green", point_colour="g",
                                  label="Atlas", size=1, orbit_previous=False),
                        orb.OrbitInfo(a=0.000, b=139400000, c=119, theta=0, line_colour="blue", point_colour="b",
                                  label="Prometheus", size=1, orbit_previous=False),
                        orb.OrbitInfo(a=0.000, b=141700000, c=105, theta=0, line_colour="purple", point_colour="m",
                                  label="Pandora", size=1, orbit_previous=False),
                        ])

Let's break this down:

We first need to know what we are looking for.

In this example, I used the data from https://en.wikipedia.org/wiki/Moons_of_Saturn#List

First, let's start with the general variables:

interval

interval is the time in milliseconds between frames. If the animation looks chunky, try increasing this. If the animation looks slow, try decreasing this. Be careful!! it can be difficult to find the right balance.

repeat

repeat is a boolean (True/False), determining whether the animation repeats once all orbits have completed.

save_name

save_name is False by default. When False, the code will not be saved on your pc. If you want to save an animation onto your pc, set save_name equal to a string (the name you want the file to be called), the animation will be saved as a gif.

a

a is the eccentricity of the orbit. You can calculate this using the calculate_eccentricity() function that is included in our library. You can also calculate it by hand using $\text{eccentricity} = \frac{\text{semi-minor axis}}{sem-major axis}$. Sometimes you can find the eccentricity online as well.

b

b is the semi-major axis. This is easiest to find online.

c

c is the angular velocity of the object. This is hard to find explicitely. Use the formula $\text{angular velocity} = \frac{2π}{\text{time period(s)}}$

NOTE: c being very small sometimes leads to issues, however usually quite they are easy to fix. If a plot comes out as a series of straight lines, try multiplying all the c values by a constant.

theta

theta is simply the initial angular position of the object. while using plot_orbit_n alone, this variable has little effect.

line_colour

line_colour is the colour you want the orbital path to be.

point_colour

point_colour is the colour you want the object to be. Unlike line_colour, this must be a single letter.

label

label is the name of the body (used in legend/key).

size

size is how big the object is.

orbit_previous

orbit_previous is a boolean (True/False). It is True by default. When True, the current object will be orbitting around the previous objects. When False, the current object will orbit the centre.

Currently, if orbit_previous is True, it will orbit all previous orbits. This will usually not be a problem, however if you are modelling, for instance, Murcury, Venus, Earth going around the sun, and the moon going around the Earth, the Earth must before both Murcury and Venus, with the moon directly afterwards.

Bringing it back

Looking back to the code above, hopefully you can see where all my values came from.

Unfortunately this none of our computers were able to save this animation due to its size, however the finished orbits should look something similar to the following:

See Here

I will now show another example that has stacking orbits (orbit_previous = True). Disclaimer: The following example is going to look odd, it is random numbers to demonstate how much variety orbits can have.

import orbipy as orb

orb.animate_orbit_n(interval=100, orbits=[orb.OrbitInfo(a=0.430, b=100, theta=0, line_colour="pink", point_colour="r",
                                  label="Donkey", size=10, orbit_previous=True),
                        orb.OrbitInfo(a=0.500, b=10, c=4, theta=5, line_colour="purple", point_colour="m",
                                  label="Penguin", size=1, orbit_previous=True),
                        orb.OrbitInfo(a=0.030, b=50, c=0.015, theta=0, line_colour="blue", point_colour="y",
                                  label="Dolphin", size=1, orbit_previous=True),
                        orb.OrbitInfo(a=0.009, b=25, c=52, theta=65, line_colour="orange", point_colour="g",
                                  label="Quail", size=1, orbit_previous=True),
                        orb.OrbitInfo(a=0.132, b=15, c=9.08, theta=73, line_colour="red", point_colour="c",
                                  label="Field Mouse", size=1, orbit_previous=True),
                        orb.OrbitInfo(a=0.080, b=250, c=20, theta=221, line_colour="green", point_colour="b",
                                  label="Guinea Pig", size=1, orbit_previous=True),
                        orb.OrbitInfo(a=0.034, b=5, c=21, theta=9, line_colour="black", point_colour="k",
                                  label="Elephant", size=1, orbit_previous=True),
                        ])

See Here

Explanation

How Mathematics has been implemented in OrbiPy

OrbiPy covers multiple different parts of mechanics, but its main purpose is to aid work involving eliptical orbit. The mathematical parts of OrbiPy are what we have been refering to as "Number Crunching" functions. The majority of these functions essentially take the inputs, fit them into an appropriate equation, then spit out the requested variable.

The majority of these functions can determine any unknown from the equation, despite their names implying single usage. This is because people often think of functions in terms of a specific variable, e.g. $F=ma$ is (in general) thought of as an equation for Force, not mass or acceleration. We also believe this naming system will make it easier for users distinguish between functions.

If you are not sure which function to use, all functions are listed with their abilities in the How To section, all functions are also listed in References (if you want a consise list).

How the Mathematics works

calculate_gravitational_pull

$$F = \frac{G M_1 M_2}{r ^ 2}$$

This is Newton's law of universal gravitation. It proposes that every body of mass attracts each other in the universe, with the magnitude of the force being directly proportional to the product of the masses, and inversely proportional to the square of the distance between them.

Brief History

This equation was first published in Newton's Philosophiæ Naturalis Principia Mathematica (1687) and was a result of Newton applying his law's of motion to Keplar's laws of planetary motion. It was originally in the form $\text{Force of gravity} \propto \frac{\text{mass of object 1} \times {\text{ mass of object 2}}} {\text{distance from centers}^2} $. The gravitational constant G was then added to turn this into an equation.

calculate_kinetic_energy

$$KE = (m (v ^ 2)) / 2$$

This equation is the second law of motion and is used to calculate the kinetic energy of an object from it's mass and velocity. It can be derived using the equation for work done $(W = F \times S)$ and Newton's second law $(F = ma)$.This form of the equation is commonly used in Classical Mechanics and is often modified to be better suited in other fields such as fluid dynamics.

Brief History

Gottfried Leibniz and Johann Bernoulli were pioneers in developing $KE \propto mv^2$ which were backed up by Willem's Gravesande's experimental data after Émilie du Châtelet recognised and published the link between them.

calculate_gravitational_potential_energy

$$GPE = (m g r)$$

This equation calculates the gravitational potential energy of an object using its mass, the accerleration due to gravity and the height of the object. The gravitational potential energy is mainly converted into kinetic energy of an object when it gets closer to another object and kinetic energy is mainly converted into gravitational potential energy when the object get further away from the other object.

calculate_gravitational_acceleration

$$g = (GM)/r^2$$

This equation calculates the gravitational acceleration of an object from its mass and radius alongside the gravitational constant. Objects that have a different mass and radius will have a different value for g. For example, the gravitational acceleration on Earth is aproximately $9.81 ms^{-2}$ whereas the gravitational acceleration on The Moon is approximately $ 1.62 ms^{-2} $ as they both have a different mass and radius.

calculate_masses_angular_position

$$\theta = t(\frac{G M}{r^3})^{\frac{1}{2}}$$

This equation calculates the angular position of an object using its mass, radius, difference in time with respect to the distance the object is away from the origin, and the gravitational constant. This equation can be derived from Keplar's third law.

calculate_linear_velocity

$$v = \frac{θ r}{t}$$

This calculates the velocity of an object at a specific time using its angle theta, radius and the time taken for the object to complete one orbit. The direction of the velocity is in a straight line as if the object suddenly stopped orbiting and started travelling in a straight line.

calculate_time_period_of_orbit

$$T = \sqrt{\frac{4 \pi ^ 2 r ^ 3 }{G M}}$$

This is Keplar's Third Law. It calculates the the time taken for an object to complete a full orbit using its mass and radius in conjunction with the gravitational constant.

calculate_electrostatic_force

$$F = \frac{G Q q}{r ^ 2}$$

This equation is similar to Newton's law of universal gravitation however instead of deriving from $F=ma$ it derives from Coulomb's Law. This calculates the electrostatic force between two particles using their charges, the distance between them and k which is Couloumb's constant.

Brief History

Joseph Priestly was the first to suggest that the inverse square law can be used to find a formula for electrostatic force. Henry Cavendish developed this formula however did not publish his findings. Charles-Augustin de Coulomb was then the first to publish this formula leading to the developement of electromagnetism.

calculate_charges_angular_position

$$\theta = T (\frac{kQ}{r ^ 3}) ^ {\frac{1}{2}}$$

This equation is similar to the calculation of a masses angular position. The angular postition of the charge is given using its charge, radius and time taken to complete a full orbit as well as using Coloumb's Constant.

parralax

$$ d = \frac{1}{\theta}$$

This equation gives the distance of the orbiting object from the Earth in parsecs by calculating the inverse of the parallax angle in arcsecs. This is very useful in calculating the distance of faraway stars in relation to Earth. A parsec is a specific unit used to calculate far away objects with 1 parsec being equal to approximately 3.26 light years.

redshift_distance

$d = \frac{c z} {H}$

This equation calculates the distance between the Earth and a far away star by using the value of the redshift, the speed of light and hubble's Constant.

calculate_velocity_from_H

$v=\frac{d}{H}$

This equation calculates the velocity of a far away star that is travelling from or towards the Earth by using its distance and Hubble's Constant.

redshift_z

$z=\frac{(\lambda_o-\lambda_r)}{\lambda_r}$

This equation calculates the redshift of a star using the change in wavelength over the wavelength. The redshift of a star is the increase of wavelength in relation to the decreasing frequency and energy of the electromagnetic radiation emitted from the star.

calculate_eccentricity

$e = \frac{c}{a}$

This calculates the eccentricity of an ellipse using the length of the semi-minor axis and the length of the semi-major axis. The eccentricity of an ellipse is essentially how 'flat' or 'round' the ellipse is. The greater the eccentricity the more 'flat' the ellipse is.

orbital_parameters

  • $r=\frac{c(1-b^2)}{(1+b(cos(wt+θ)))}$
  • $v=\frac{1}{(wr)}$
  • $Ke=(\frac{1}{2})mv^2$
  • $Gpe=\frac{(GMm)}{r}$
  • $x=rcos(wt+θ)$
  • $y=rsin(wt+θ)$

This function uses these equations using data of the orbiting object including its x and y coordinates to give a tuple of all of these values. This tuple can then be used to graph the orbit of this object.

plot_orbit_n

  • $r=\frac{b(1-a^2)}{1+a(cos(ct+θ))}$
  • $x=r(cos(ct+θ))$
  • $y=r(sin(ct+θ))$

These equations are used in this function to plot the first n elliptical orbits with 6 variables for each orbit.

animate_orbit_n

This function animates the graph of the orbit above so you can see the path the orbiting object takes.

References

Functionality of library

OrbiPy contains the following functions:

Number Crunching

  • calculate_gravitational_pull
  • calculate_kinetic_energy
  • calculate_gravitational_potential_energy
  • calculate_gravitational_acceleration
  • calculate_masses_angular_position
  • calculate_linear_velocity
  • calculate_time_period_of_orbit
  • calculate_electrostatic_force
  • calculate_charges_angular_position
  • parralax
  • redshift_distance
  • calculate_velocity_from_H
  • redshift_z
  • calculate_eccentricity
  • orbital_parameters

Plots

  • plot_orbit_n

Animations

-animate_orbit_n

Bibliography

For an overview of the mathematics of orbits, the following Wikipedia page has a lot of useful information:

https://en.wikipedia.org/wiki/Orbital_mechanics

If you are interested in modelling our solar system, we suggest using this factsheet:

https://nssdc.gsfc.nasa.gov/planetary/factsheet/

Keplers' Laws:

https://www.britannica.com/science/celestial-mechanics-physics/Keplers-laws-of-planetary-motion

About

A python library for calculating and modelling orbits. Group Project with Tom Hinchey, Grace Eddy, and Szymon Klejny.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors