A convenience wrapper around [add_body_keplerian()] that looks up real orbital elements for well-known solar system bodies. Instead of typing out mass, semi-major axis, eccentricity, and inclination by hand, just give the name and parent:
Usage
add_planet(
system,
name,
parent,
nu = 0,
a = NULL,
e = NULL,
i = NULL,
lan = NULL,
arg_pe = NULL,
mass = NULL
)Arguments
- system
An `orbit_system` object.
- name
The name of the body. Must be one of: `"Mercury"`, `"Venus"`, `"Earth"`, `"Mars"`, `"Jupiter"`, `"Saturn"`, `"Uranus"`, `"Neptune"`, `"Moon"`, or `"Pluto"`. Case-sensitive.
- parent
Character id of the parent body, which must already exist in the system. For planets and Pluto this is typically `"Sun"`; for the Moon it is `"Earth"`.
- nu
True anomaly in degrees (default 0, body starts at periapsis). This is the most commonly overridden element — use it to spread planets around their orbits instead of starting them all at periapsis.
- a
Override semi-major axis (meters).
- e
Override eccentricity.
- i
Override inclination (degrees).
- lan
Override longitude of ascending node (degrees).
- arg_pe
Override argument of periapsis (degrees).
- mass
Override mass (kg).
Details
“` create_system() |> add_sun() |> add_planet("Earth", parent = "Sun") |> add_planet("Moon", parent = "Earth") “`
Any Keplerian element can be overridden to explore "what if" scenarios while keeping the rest of the real values:
“` # What if Mars had zero eccentricity? add_planet("Mars", parent = "Sun", e = 0) “`
Examples
# \donttest{
# Build the inner solar system
create_system() |>
add_sun() |>
add_planet("Mercury", parent = "Sun") |>
add_planet("Venus", parent = "Sun") |>
add_planet("Earth", parent = "Sun") |>
add_planet("Mars", parent = "Sun") |>
simulate_system(time_step = seconds_per_day, duration = seconds_per_year) |>
plot_orbits()
# Earth-Moon system
create_system() |>
add_body("Earth", mass = mass_earth) |>
add_planet("Moon", parent = "Earth") |>
simulate_system(time_step = seconds_per_hour, duration = seconds_per_day * 28) |>
plot_orbits()
# What if Jupiter were twice as massive?
create_system() |>
add_sun() |>
add_planet("Jupiter", parent = "Sun", mass = mass_jupiter * 2)
#> $bodies
#> # A tibble: 2 × 8
#> id mass x y z vx vy vz
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Sun 1.99e30 0 0 0 0 0 0
#> 2 Jupiter 3.80e27 717206783344. 183226943299. -16760108524. -3394. 13287. 21.0
#>
#> $forces
#> $forces$gravity
#> $forces$gravity$type
#> [1] "n_body_gravity"
#>
#> $forces$gravity$G
#> [1] 6.6743e-11
#>
#>
#>
#> $time
#> [1] 0
#>
#> attr(,"class")
#> [1] "orbit_system"
# }