View Source SpaceDust.Bodies.Barycenter (Space Dust v0.3.0)

Barycentric coordinate calculations for solar system bodies.

Provides functions to compute positions relative to the solar system barycenter (SSB) and the Earth-Moon barycenter (EMB). Useful for sun-centric mission planning and high-precision orbital mechanics.

Coordinate Systems

  • Heliocentric - Centered on the Sun
  • Barycentric - Centered on the solar system barycenter (SSB)
  • Geocentric - Centered on Earth (ECI)
  • Earth-Moon Barycentric - Centered on the Earth-Moon system barycenter (EMB)

For most practical purposes in Earth orbit, the SSB and Sun center are effectively equivalent. The main difference is when computing positions of outer planets or for high-precision ephemeris work.

Summary

Functions

Get the ECI position of a named body.

Get the heliocentric position of a named body.

Calculate the distance between two bodies at a given time.

Calculate Earth's position in heliocentric coordinates.

Earth mass in kg

Calculate the Earth-Moon barycenter position in ECI frame.

Earth to Moon mass ratio

Calculate orbital elements of Earth around the Sun.

Calculate Earth's position relative to the Earth-Moon barycenter.

Convert an ECI position to heliocentric coordinates.

Calculate Earth-Moon barycenter position in heliocentric coordinates.

Convert a heliocentric position to ECI coordinates.

Calculate Moon's position in heliocentric coordinates.

Moon mass in kg

Calculate Moon's position relative to the Earth-Moon barycenter.

Sun to Earth mass ratio

Sun mass in kg

Functions

body_eci_position(body, epochUtc)

@spec body_eci_position(atom(), DateTime.t()) :: SpaceDust.Math.Vector.vector()

Get the ECI position of a named body.

Parameters

  • body - Atom identifying the body (:sun, :earth, :moon, :emb)
  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Position in ECI frame (meters)

body_heliocentric_position(body, epochUtc)

@spec body_heliocentric_position(atom(), DateTime.t()) ::
  SpaceDust.Math.Vector.vector()

Get the heliocentric position of a named body.

Parameters

  • body - Atom identifying the body (:sun, :earth, :moon, :emb)
  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Position in heliocentric frame (meters)

distance_between(body1, body2, epochUtc)

@spec distance_between(atom(), atom(), DateTime.t()) :: float()

Calculate the distance between two bodies at a given time.

Parameters

  • body1 - Atom identifying first body (:sun, :earth, :moon)
  • body2 - Atom identifying second body (:sun, :earth, :moon)
  • epochUtc - DateTime in UTC

Returns

  • Distance in meters

Example

iex> SpaceDust.Bodies.Barycenter.distance_between(:earth, :moon, ~U[2024-01-01 12:00:00Z])

earth_heliocentric(epochUtc)

@spec earth_heliocentric(DateTime.t()) :: SpaceDust.Math.Vector.vector()

Calculate Earth's position in heliocentric coordinates.

Earth's heliocentric position is the negative of the Sun's geocentric position.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Earth position in heliocentric frame (meters)

Example

iex> SpaceDust.Bodies.Barycenter.earth_heliocentric(~U[2024-01-01 12:00:00Z])

earth_mass()

Earth mass in kg

earth_moon_barycenter(epochUtc)

@spec earth_moon_barycenter(DateTime.t()) :: SpaceDust.Math.Vector.vector()

Calculate the Earth-Moon barycenter position in ECI frame.

The EMB is located along the line from Earth to Moon, at a distance proportional to the mass ratio.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - EMB position in ECI frame (meters from Earth center)

Example

iex> SpaceDust.Bodies.Barycenter.earth_moon_barycenter(~U[2024-01-01 12:00:00Z])

earth_moon_mass_ratio()

Earth to Moon mass ratio

earth_orbital_elements(epochUtc)

@spec earth_orbital_elements(DateTime.t()) :: map()

Calculate orbital elements of Earth around the Sun.

Returns basic orbital parameters for Earth's heliocentric orbit at the given epoch.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • Map with orbital elements:
    • :semi_major_axis - Semi-major axis in meters
    • :distance - Current distance from Sun in meters
    • :true_anomaly - True anomaly in radians
    • :mean_anomaly - Mean anomaly in radians (approximate)

earth_position_emb(epochUtc)

@spec earth_position_emb(DateTime.t()) :: SpaceDust.Math.Vector.vector()

Calculate Earth's position relative to the Earth-Moon barycenter.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Earth position in EMB frame (meters)

eci_to_heliocentric(eci_position, epochUtc)

Convert an ECI position to heliocentric coordinates.

Parameters

  • eci_position - Position vector in ECI frame (meters)
  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Position in heliocentric frame (meters)

emb_heliocentric(epochUtc)

@spec emb_heliocentric(DateTime.t()) :: SpaceDust.Math.Vector.vector()

Calculate Earth-Moon barycenter position in heliocentric coordinates.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - EMB position in heliocentric frame (meters)

heliocentric_to_eci(helio_position, epochUtc)

Convert a heliocentric position to ECI coordinates.

Parameters

  • helio_position - Position vector in heliocentric frame (meters)
  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Position in ECI frame (meters)

moon_heliocentric(epochUtc)

@spec moon_heliocentric(DateTime.t()) :: SpaceDust.Math.Vector.vector()

Calculate Moon's position in heliocentric coordinates.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Moon position in heliocentric frame (meters)

moon_mass()

Moon mass in kg

moon_position_emb(epochUtc)

@spec moon_position_emb(DateTime.t()) :: SpaceDust.Math.Vector.vector()

Calculate Moon's position relative to the Earth-Moon barycenter.

Parameters

  • epochUtc - DateTime in UTC

Returns

  • %Vector3D{} - Moon position in EMB frame (meters)

sun_earth_mass_ratio()

Sun to Earth mass ratio

sun_mass()

Sun mass in kg