add_body_keplerian(id, mass, a, e=0, i=0, lan=0, arg_pe=0, nu=0, *, parent)
Add a body using Keplerian orbital elements.
Describes an orbit by its size, shape and orientation instead of a raw position and velocity. The six elements are converted to a position and velocity relative to the parent body, which must already be in the system, and the parent’s own position and velocity are then added on. Use this when you know what the orbit looks like (for example from a table of orbital elements) rather than where the body is at one instant. Also available as orb.add_body_keplerian(system, ...).
Six numbers fully describe a Keplerian orbit:
a, the semi-major axis, sets the size: half the longest diameter of the ellipse.
e, the eccentricity, sets the shape: 0 is a circle, values between 0 and 1 are ellipses, values above 1 are hyperbolas.
i, the inclination, is the tilt of the orbital plane away from the reference plane (the xy plane).
lan, the longitude of the ascending node (often written \(\Omega\)), is the angle from the x axis to the point where the orbit crosses the reference plane going upward.
arg_pe, the argument of periapsis (often written \(\omega\)), is the angle within the orbital plane from the ascending node to the point of closest approach.
nu, the true anomaly, is where the body is along its orbit right now, measured as an angle from periapsis.
Parameters
Name
Type
Description
Default
id
str
A unique name for the body.
required
mass
float
Mass in kilograms. Must be zero or positive.
required
a
float
Semi-major axis in meters. Positive for an ellipse (e < 1) and negative for a hyperbola (e > 1). It cannot be 0.
required
e
float
Eccentricity, with no units. 0 is a circle, between 0 and 1 is an ellipse, above 1 is a hyperbola. Exactly 1 (a parabola) is not supported. Default 0.
0
i
float
Inclination in degrees. Default 0, which puts the orbit in the xy plane.
0
lan
float
Longitude of the ascending node in degrees. Default 0.
0
arg_pe
float
Argument of periapsis in degrees. Default 0.
0
nu
float
True anomaly in degrees. 0 is periapsis (closest to the parent) and 180 is apoapsis (farthest). Default 0, so the body starts at periapsis.
0
parent
str
The name of the body being orbited, which must already be in the system. The elements are defined relative to this body. Must be passed by keyword.
required
Returns
Name
Type
Description
OrbitSystem
A new system with the body added. Its stored state is a position (m) and velocity (m/s) in the same frame as the rest of the system. The original system is not modified.
Raises
Name
Type
Description
ValueError
If parent is not in the system; if e is negative or exactly 1; if a is 0, negative with e < 1, or positive with e > 1; if G or the parent’s mass is zero (there is then no orbit to describe; use add_body()); if nu lies outside the asymptotes of a hyperbola; or if id or mass fail the checks in add_body().
With \(\mu = G M_\text{parent}\), the distance from the parent at true anomaly \(\nu\) is
\[r = \frac{a (1 - e^2)}{1 + e \cos\nu}\]
and the specific angular momentum is \(h = \sqrt{\mu a (1 - e^2)}\). The position and velocity are worked out in the plane of the orbit, with x pointing at periapsis, and then rotated by arg_pe, i and lan into the system’s frame. With i, lan and arg_pe all 0, periapsis lies on the positive x axis and the body moves counterclockwise seen from positive z.
Only the parent’s mass enters \(\mu\). The new body’s own mass is ignored when its speed is set, which is accurate when the body is much lighter than its parent. For two bodies of similar mass the simulated orbit will differ from the elements you asked for.
A hyperbolic orbit (\(e > 1\)) is an unbound flyby: the body arrives from far away, swings past the parent once, and leaves. By convention its semi-major axis is negative, and the closest approach is still \(a (1 - e)\). A hyperbola only exists between its two asymptotes, so the true anomaly must satisfy \(|\nu| < \arccos(-1/e)\).
───────────────────────────────── orbit_system ─────────────────────────────────
G: 6.6743e-11 (standard)
Bodies: 2
id mass x y z vx vy vz
Sun 1.989000e+30 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 0.00000 0.000000
Mars 6.417000e+23 1.887900e+11 -8.370696e+10 -6.395443e+09 10749.771467 24226.11646 243.021783
A hyperbolic flyby: e above 1 with a negative a. The comet starts at periapsis, 1e11 m from the Sun.