A convenience function that adds the Sun as the central body of a simulation. By default it is placed at the origin with zero velocity, which is the natural choice for a heliocentric reference frame. Position and velocity can be overridden for advanced use cases such as barycentric coordinates.
Arguments
- system
An `orbit_system` object created by [create_system()].
- mass
Mass of the Sun in kilograms. Defaults to [mass_sun] (1.989 x 10^30 kg).
- x
Initial X-axis position in meters (default 0).
- y
Initial Y-axis position in meters (default 0).
- z
Initial Z-axis position in meters (default 0).
- vx
Initial velocity along the X-axis in m/s (default 0).
- vy
Initial velocity along the Y-axis in m/s (default 0).
- vz
Initial velocity along the Z-axis in m/s (default 0).
Details
This pairs naturally with [add_planet()]:
“` create_system() |> add_sun() |> add_planet("Earth", parent = "Sun") |> add_planet("Mars", parent = "Sun") “`
Examples
# Typical usage — Sun at the origin
create_system() |>
add_sun()
#> ───────────────────────────────── orbit_system ─────────────────────────────────
#> G: 6.6743e-11 (standard)
#> Bodies: 1
#>
#> # A tibble: 1 × 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
# \donttest{
# Full solar system in three lines
create_system() |>
add_sun() |>
add_planet("Earth", parent = "Sun") |>
add_planet("Mars", parent = "Sun") |>
simulate_system(time_step = seconds_per_day, duration = seconds_per_year) |>
plot_orbits()
# }