add_sun: Add the Sun to the system

View source: R/add_sun.R

add_sunR Documentation

Add the Sun to the system

Description

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.

Usage

add_sun(system, mass = mass_sun, x = 0, y = 0, z = 0, vx = 0, vy = 0, vz = 0)

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") “'

Value

The updated 'orbit_system' with the Sun added.

Examples

# Typical usage — Sun at the origin
create_system() |>
  add_sun()


# 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()


orbitr documentation built on Oct. 2, 2026, 1:06 a.m.