Skip to main content

OrbitSystem.add_body

add_body(id, mass, x=0, y=0, z=0, vx=0, vy=0, vz=0)

Add a body by its position and velocity.

Adds a point mass with a given starting position and velocity (its Cartesian state vector). This is the most general way to place a body: you say exactly where it is and how it is moving. To describe an orbit by its shape instead, use add_body_keplerian(), and for a real planet use add_planet(). Also available as orb.add_body(system, ...).

Parameters

Name Type Description Default
id str A unique name for the body, such as "Earth". It labels the body in the results and is how other functions refer to it. required
mass float Mass in kilograms. Must be zero or positive. A mass of 0 gives a test particle that feels gravity but exerts none. required
x float Initial position along the x axis, in meters. Default 0. 0
y float Initial position along the y axis, in meters. Default 0. 0
z float Initial position along the z axis, in meters. Default 0. 0
vx float Initial velocity along the x axis, in meters per second. Default 0. 0
vy float Initial velocity along the y axis, in meters per second. Default 0. 0
vz float Initial velocity along the z axis, in meters per second. Default 0. 0

Returns

Name Type Description
OrbitSystem A new system with the body added as the last row. The original system is not modified.

Raises

Name Type Description
ValueError If a body named id already exists, if mass is not a single number, or if mass is negative.

See Also

Examples

The Earth and the Moon. The Earth sits at the origin and the Moon starts on the x axis, moving in the y direction at its mean orbital speed.

import pyorbiter as orb

system = (
    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)
)
system
───────────────────────────────── orbit_system ─────────────────────────────────
G: 6.6743e-11 (standard)
Bodies: 2

   id         mass           x   y   z  vx     vy  vz
Earth 5.972000e+24         0.0 0.0 0.0 0.0    0.0 0.0
 Moon 7.342000e+22 384400000.0 0.0 0.0 0.0 1022.0 0.0

Simulate it for 28 days.

import pyorbiter as orb

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=28 * orb.seconds_per_day)
)
sim.tail()
id mass x y z vx vy vz time
1341 Moon 7.342000e+22 3.774621e+08 1.020141e+08 0.0 -192.592369 1003.552822 0.0 2412000.0
1342 Earth 5.972000e+24 9.402939e+04 2.905228e+07 0.0 2.484865 0.250018 0.0 2415600.0
1343 Moon 7.342000e+22 3.767516e+08 1.056235e+08 0.0 -202.119499 1001.663479 0.0 2415600.0
1344 Earth 5.972000e+24 1.031855e+05 2.905323e+07 0.0 2.601766 0.274366 0.0 2419200.0
1345 Moon 7.342000e+22 3.760069e+08 1.092260e+08 0.0 -211.628284 999.682981 0.0 2419200.0