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()
#> $bodies
#> # 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
#>
#> $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"
# \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()
# }