gravity

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	G        float64 = 6.6725985e-11
	Pi       float64 = 3.14159265358979
	Epsilon  float64 = 1e-15 // very small number
	Epsilon6 float64 = 1e-06 // small number
)

Variables

This section is empty.

Functions

func Apoapsis

func Apoapsis(a, e float64) float64

Apoapsis distance (m).

a: semi-major axis (m), e: eccentricity (0-1).

https://en.wikipedia.org/wiki/Apsis

func Degrees

func Degrees(rad float64) float64

Degrees from radians.

func EccentricAnomaly added in v0.3.0

func EccentricAnomaly(e float64, m float64) float64

EccentricAnomaly (rad) using Newton's method.

e: eccentricity (0-1), m: mean anomaly (rad).

http://www.csun.edu/~hcmth017/master/node16.html

func Force

func Force(p1 f64.Vec3, p2 f64.Vec3, m1 float64, m2 float64) f64.Vec3

Force vector due to gravity (N) using Netwon's law of universal gravitation.

p1: position of the primary body (m), p2: position of the secondary body (m), m1: mass of the primary body (kg), m2: mass of the secondary body (kg).

apply {-x, -y, -z} to b1, apply {x, y, z} to b2.

https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Vector_form

func OrbitalElements

func OrbitalElements(r f64.Vec3, v f64.Vec3, m1 float64, m2 float64) (a, e, w, lan, i, m float64)

OrbitalElements from Cartesian State Vectors.

accepts: r: position relative to primary body (m), v: velocity relative to primary body (m/s), m1: mass of the primary body (kg), m2: mass of the secondary body (kg).

returns: a: semi-major axis (m), e: eccentricity (0-1), w: argument of periapsis (rad), lan: longitude of ascending node (rad), i: inclination (rad), m: mean anomaly (rad).

The various singularities are removed by applying the following transformations where epsilon (eps) is equal to 1e-15. While the transformations are clearly not ideal it is the best I can do for now with my limited math knowledge.

rZ=0 -> rZ=eps, vZ=0 -> vZ=eps, e=0 -> e=eps, i=0 -> i=eps, i=Pi -> i=Pi-eps [180 (deg) = Pi (rad)].

If the primary body is on-rails then set m2 to 0. If you don't set m2 to 0 then the elements will be predicted based on the bodies both orbiting their combined center of mass which is incorrect if the primary body is on-rails.

https://downloads.rene-schwarz.com/download/M002-Cartesian_State_Vectors_to_Keplerian_Orbit_Elements.pdf

func Periapsis

func Periapsis(a, e float64) float64

Periapsis distance (m).

a: semi-major axis (m), e: eccentricity (0-1).

https://en.wikipedia.org/wiki/Apsis

func Period

func Period(a, m1, m2 float64) float64

Period (s).

a: semi-major axis (m), m1: mass of the primary body (kg), m2: mass of the secondary body (kg).

If the primary body is on-rails then set m2 to 0. See OrbitalElements for more details.

https://en.wikipedia.org/wiki/Orbital_period

func Radians

func Radians(deg float64) float64

Radians from degrees.

func StateVectors

func StateVectors(a, e, w, lan, i, m0, t, m1, m2 float64) (f64.Vec3, f64.Vec3)

StateVectors at t seconds after epoch from Keplerian Orbital Elements.

accepts: a: semi-major axis (m), e: eccentricity (0-1), w: argument of periapsis (rad), lan: longitude of ascending node (rad), i: inclination (rad), m0: mean anomaly at epoch (rad), t: time since epoch (seconds), m1: mass of the primary body (kg), m2: mass of the secondary body (kg).

returns: r: position relative to primary body (m), v: velocity relative to primary body (m/s).

If the primary body is on-rails then set m2 to 0. See OrbitalElements for more details.

https://downloads.rene-schwarz.com/download/M001-Keplerian_Orbit_Elements_to_Cartesian_State_Vectors.pdf

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL