Skip to main content

Built-In Physical Constants

The masses, distances, orbital speeds, and time conversions that ship with pyorbiter, all in SI units.

pyorbiter ships a set of real-world masses, distances, and orbital speeds so you do not have to look them up every time. All values are in SI units: kilograms, meters, and meters per second.

Every constant is a plain Python number at the top level of the package:

import pyorbiter as orb

orb.mass_earth, orb.distance_earth_sun, orb.speed_earth
(5.972e+24, 149600000000.0, 29780)

The tables on this page are built from the package itself when the site is rendered, so they always show the values you get when you import it. The names come from orb.constants.__all__, and this small helper turns the ones that share a prefix into a table:

import pandas as pd

def constants_table(prefix, unit, fmt):
    names = [name for name in orb.constants.__all__ if name.startswith(prefix)]
    names.sort(key=lambda name: getattr(orb, name))
    return pd.DataFrame({
        "value": [format(getattr(orb, name), fmt) for name in names],
        "unit": unit,
    }, index=pd.Index(names, name="constant"))

The gravitational constant

constants_table("gravitational", "m^3 kg^-1 s^-2", ".4e")
value unit
constant
gravitational_constant 6.6743e-11 m^3 kg^-1 s^-2

This is the default G of create_system().

Time conversions

constants_table("seconds", "s", ",.0f")
value unit
constant
seconds_per_hour 3,600 s
seconds_per_day 86,400 s
seconds_per_year 31,557,600 s

A year here is a Julian year of 365.25 days. These are the natural way to write time_step and duration, for example duration=28 * orb.seconds_per_day.

Masses

constants_table("mass", "kg", ".3e")
value unit
constant
mass_pluto 1.309e+22 kg
mass_moon 7.342e+22 kg
mass_mercury 3.301e+23 kg
mass_mars 6.417e+23 kg
mass_venus 4.867e+24 kg
mass_earth 5.972e+24 kg
mass_uranus 8.681e+25 kg
mass_neptune 1.024e+26 kg
mass_saturn 5.683e+26 kg
mass_jupiter 1.898e+27 kg
mass_sun 1.989e+30 kg

Orbital distances (semi-major axes)

constants_table("distance", "m", ".3e")
value unit
constant
distance_earth_moon 3.844e+08 m
distance_mercury_sun 5.791e+10 m
distance_venus_sun 1.082e+11 m
distance_earth_sun 1.496e+11 m
distance_mars_sun 2.279e+11 m
distance_jupiter_sun 7.785e+11 m
distance_saturn_sun 1.434e+12 m
distance_uranus_sun 2.871e+12 m
distance_neptune_sun 4.495e+12 m
distance_pluto_sun 5.906e+12 m

distance_earth_moon is the Moon’s distance from Earth. The others are distances from the Sun.

Mean orbital speeds

constants_table("speed", "m/s", ",.0f")
value unit
constant
speed_moon 1,022 m/s
speed_pluto 4,740 m/s
speed_neptune 5,430 m/s
speed_uranus 6,800 m/s
speed_saturn 9,680 m/s
speed_jupiter 13,060 m/s
speed_mars 24,070 m/s
speed_earth 29,780 m/s
speed_venus 35,020 m/s
speed_mercury 47,360 m/s

speed_moon is the Moon’s speed around Earth. The others are speeds around the Sun.

Using the constants

With the constants, the Earth-Moon example can be written without a single number looked up by hand:

sim = (
    orb.create_system()
    .add_body("Earth", mass=orb.mass_earth)
    .add_body("Moon", mass=orb.mass_moon, x=orb.distance_earth_moon, vy=orb.speed_moon)
    .simulate(time_step=orb.seconds_per_hour, duration=orb.seconds_per_day * 28)
)

orb.plot_orbits(sim);

The same constants are behind add_sun(), add_planet(), and load_solar_system(), which use these masses and semi-major axes together with each body’s eccentricity and orientation.

Why the “distance” constants are semi-major axes

Orbital distances are not truly constant. Every orbit is an ellipse, so the separation between two bodies changes continuously through each revolution. The values provided here are semi-major axes: the average of the closest approach (periapsis) and the farthest point (apoapsis).

The semi-major axis \(a\) is the most characteristic length scale of an elliptical orbit. It sets the orbital period through Kepler’s third law,

\[ T = 2\pi \sqrt{\frac{a^3}{G M}}, \]

where \(M\) is the mass of the central body (strictly, the sum of the two masses). For Earth around the Sun the constants give a period of very nearly one year:

import math

period = 2 * math.pi * math.sqrt(
    orb.distance_earth_sun**3 / (orb.gravitational_constant * orb.mass_sun)
)
period / orb.seconds_per_day
365.21050633813775

You can see the distance vary in a simulation. add_planet() gives Earth its real eccentricity of 0.0167, so over one year the Earth-Sun separation swings between perihelion and aphelion:

sim = (
    orb.create_system()
    .add_sun()
    .add_planet("Earth", parent="Sun")
    .simulate(time_step=orb.seconds_per_hour, duration=orb.seconds_per_year)
)

earth = orb.shift_reference_frame(sim, "Sun")
earth = earth[earth["id"] == "Earth"]
distance_km = (earth["x"] ** 2 + earth["y"] ** 2 + earth["z"] ** 2) ** 0.5 / 1000

distance_km.agg(["min", "max", "mean"]) / 1e6
min     147.101680
max     152.097431
mean    149.619834
dtype: float64

The separation runs from about 147.1 million km at perihelion to about 152.1 million km at aphelion. The semi-major axis of 149.6 million km sits in the middle of that range, and it is the value that gives the correct one-year period.

Why the “speed” constants give nearly circular orbits

Paired with the mean orbital speed, the semi-major axis produces a nearly circular trajectory that closely approximates the real orbit. The speed of a circular orbit of radius \(a\) is

\[ v = \sqrt{\frac{G M}{a}}, \]

and the built-in mean speeds are close to that value for each planet:

planets = ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"]

pd.DataFrame({
    "mean speed (m/s)": [getattr(orb, f"speed_{p}") for p in planets],
    "circular speed (m/s)": [
        round(math.sqrt(orb.gravitational_constant * orb.mass_sun / getattr(orb, f"distance_{p}_sun")))
        for p in planets
    ],
}, index=pd.Index(planets, name="planet"))
mean speed (m/s) circular speed (m/s)
planet
mercury 47360 47879
venus 35020 35027
earth 29780 29789
mars 24070 24135
jupiter 13060 13058
saturn 9680 9622
uranus 6800 6800
neptune 5430 5434
pluto 4740 4741

The two columns agree to within about one percent (Mercury is the furthest off), and for most planets much more closely. The small differences are why a body started with x=orb.distance_earth_sun, vy=orb.speed_earth traces a slightly elliptical orbit and not a perfect circle.

If you want a clearly elliptical orbit, start the body at periapsis with a faster-than-circular velocity, or at apoapsis with a slower one. Building Two-Body Orbits works through the choices, and Keplerian Orbital Elements shows how to ask for a given eccentricity directly.