Skip to content

Commit 6499915

Browse files
authored
docs(AstrodynamicalCalculations): add usage examples (#265)
## Changes --- Reviewer: @cadojo
1 parent 8cd29ca commit 6499915

File tree

7 files changed

+420
-5
lines changed

7 files changed

+420
-5
lines changed

lib/AstrodynamicalCalculations/docs/src/_quarto.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ book:
1010
date: "2025-03-02"
1111
chapters:
1212
- index.md
13+
- part: examples/index.qmd
14+
chapters:
15+
- examples/circular-two-body/index.qmd
16+
- examples/keplerian/index.qmd
17+
- examples/circular-three-body/index.qmd
1318
- part: api/index.qmd
1419
chapters:
1520
- api/r2b/index.qmd
@@ -34,10 +39,8 @@ book:
3439
toc-title: "Table of Contents"
3540

3641
execute:
37-
echo: false
42+
echo: true
3843
output: true
39-
cache: false
40-
freeze: false
4144

4245
bibliography: references.bib
4346

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
number-depth: 2
3+
---
4+
5+
# Orbits in Circular Three Body Dynamics
6+
7+
*Orbits in e.g. the Earth-Moon system.*
8+
9+
```{julia}
10+
using LinearAlgebra
11+
using AstrodynamicalCalculations
12+
```
13+
14+
## Coordinate Conversions
15+
16+
The Circular Restricted Three Body (CR3B) Problem describes a massless spacecraft experiencing gravitational forces due to *two* point masses which orbit their common center of mass.
17+
There's a good bit there, so let's unpack that statement further.
18+
Consider the Earth and its moon.
19+
The Earth and the Moon both orbit the Sun, but if we neglect the Sun and watch the positions of the Earth and the Moon with respect to their common center of mass (in a rotating reference frame where the $\hat{x}$ axis points from the Earth to the Moon) then both the Earth and the Moon appear to move along *circular* orbits.
20+
21+
When we analyze orbits within this problem, we typically use non-dimensional units: we scale all distance units by the distance $a$ between the two massive bodies, and we scale all time distances by the following function of $a$ and each body's mass parameter: $2\pi \sqrt{\frac{a^3}{\mu_1 + \mu_2}}$.
22+
23+
```{julia}
24+
a = 1e5 # TODO replace with real value
25+
μ₁ = 1e5 # TODO replace with real value
26+
μ₂ = 14 # TODO replace with real value
27+
```
28+
29+
Both of these scalings are provided by the `distance_scaling` and `time_scaling` functions.
30+
The `velocity_scaling` is simply the result of the `distance_scaling` divided by the `time_scaling`.
31+
32+
```{julia}
33+
L = distance_scaling(a, μ₁, μ₂)
34+
```
35+
36+
```{julia}
37+
T = time_scaling(a, μ₁, μ₂)
38+
```
39+
40+
```{julia}
41+
V = velocity_scaling(a, μ₁, μ₂)
42+
```
43+
44+
These scalings are applied to Cartesian state vectors in CR3B dynamics.
45+
46+
```{julia}
47+
c = (; x = 1e6, y = -1e2, z = 3e3, ẋ = 1e2, ẏ = -1e3, ż = 0.0)
48+
t = 1e9
49+
50+
c = nondimensional(c..., t, a, μ₁, μ₂)
51+
```
52+
53+
::: {.callout-important appearance="simple"}
54+
All CR3B calculations are performed using **nondimensional** units in the Synodic (rotating) reference frame!
55+
:::
56+
57+
Given a particular Synodic (rotating reference frame) position $\overrightarrow{x}$, we can also compute the corresponding distance to the primary and secondary bodies using `distance_to_primary` and `distance_to_secondary` respectively.
58+
59+
```{julia}
60+
r = norm((c.x, c.y, c.z))
61+
```
62+
63+
```{julia}
64+
r₁ = distance_to_primary(r, c.μ)
65+
```
66+
67+
```{julia}
68+
r₂ = distance_to_secondary(r, c.μ)
69+
```
70+
71+
As mentioned above, all calculations are performed in the Synodic (rotating) reference frame.
72+
We can convert nondimensional Cartesian coordinates expressed in the Synodic frame to the barycentric inertial frame (an inertial frame centered at the center of mass of the system) using the `synodic_to_inertial` function with two additional pieces of information: the time $t$ since the coordinate frame epoch and the angular speed of the massive bodies $\omega$.
73+
74+
```{julia}
75+
let t = 0.1, ω = 1.0
76+
synodic_to_inertial(c.x, c.y, c.z, t, ω)
77+
end
78+
```
79+
80+
## Energy Calculations
81+
82+
As always, we can compute the potential energy of the orbit using the `potential_energy` function.
83+
84+
```{julia}
85+
P = potential_energy(c.x, c.y, c.z, c.μ)
86+
```
87+
88+
There is a second metric for measuring orbital energies in CR3B dynamics: the so-called Jacobi constant $C \triangleq 2 P - v^2$.
89+
We can use the `jacobi_constant` function to compute this value.
90+
91+
```{julia}
92+
C = jacobi_constant(c.x, c.y, c.z, c.ẋ, c.ẏ, c.ż, c.μ)
93+
```
94+
95+
Every CR3B system has the potential for *contours* of zero-velocity dynamics: a spacecraft in the system may never cross such lines in state space.
96+
The `zero_velocity_curves` function computes these contours as collections of $(x,y)$ lines.
97+
98+
## Lagrange Points
99+
100+
As is the case for all nonlinear dynamical systems, there are special positions in state space where the induced accelerations are null.
101+
In CR3B dynamics, these points are known as Lagrange points.
102+
In theory, a spacecraft placed at one of these points will stay there for all time.
103+
In practice, of course, no system perfectly satisfies the assumptions set by the CR3B definition.
104+
Still, these points *are* practically useful, as demonstrated by e.g. the James Webb Space Telescope's orbit about an Earth-Moon Lagrange point.
105+
106+
There are $5$ Lagrange points for every CR3B system: three along the $x$ axis, and two offset points which are mirrored across the $x$ axis.
107+
The positions for each of these points can be found using the `lagrange_point` function, given the nondimensional mass parameter $\mu$ for the CR3B system.
108+
109+
```{julia}
110+
let L = 1:5
111+
L .=> lagrange_point.(c.μ, L)
112+
end
113+
```
114+
115+
## Approximate Periodic Orbits
116+
117+
There exist periodic orbits about Lagrange points in CR3B dynamics.
118+
Periodic orbits in three dimensions (extra-planar orbits) are known as *halo* orbits.
119+
Periodic orbits in two dimensions (planar orbits) are known as *Lyapunov* orbits.
120+
These orbits can only be found using (quite sensitive) numerical methods: these capabilities are provided by `AstrodynamicalSolvers.jl`, and are described in the package [documentation](https://JuliaAstro.org/GeneralAstrodynamics/lib/AstrodynamicalSolvers).
121+
Approximations for periodic initial conditions are available analytically, and this is provided in `AstrodynamicalCalculations` through the `richardson_ic` function.
122+
123+
```{julia}
124+
let L = 2, Z = 1e-3
125+
ic = richardson_ic(c.μ, L; Z = Z)
126+
end
127+
```
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
number-depth: 2
3+
---
4+
5+
# Circular Orbits
6+
7+
_The simplest possible orbit._
8+
9+
```{julia}
10+
using LinearAlgebra
11+
using AstrodynamicalCalculations
12+
```
13+
14+
## Coordinate Conversions
15+
16+
If we assume a mass-less spacecraft orbiting a point mass, perfectly circular orbits are possible.
17+
The eccentricity of circular orbits is (by definition) zero.
18+
We can confirm this using the `conic` function.
19+
20+
```{julia}
21+
let e = 0
22+
conic(e)
23+
end
24+
```
25+
26+
We can construct a fully specified circular orbit by specifying Keplerian parameters (orbital elements).
27+
The mass parameter `μ` is the mass of the body we are orbiting multiplied by gravitational constant $G$.
28+
29+
```{julia}
30+
k = (; e = 0, a = 10e5, i = π / 4, Ω = 0, ω = 0, ν = π / 2)
31+
μ = 3.1e10
32+
```
33+
34+
With our orbit specified in Keplerian parameters, we may ask: what are the Cartesian coordinates of the orbit?
35+
36+
:::{.callout-info appearance="simple"}
37+
The Cartesian coordinates are defined _with respect to_ the center of the primary body (the body that is being orbited), and _expressed in_ the coordinate frame defined by the primary body.
38+
:::
39+
40+
```{julia}
41+
c = keplerian_to_cartesian(k..., μ)
42+
```
43+
44+
We can also take Cartesian coordinates and convert them back to Keplerian coordinates.
45+
46+
:::{.callout-warning appearance="simple"}
47+
The transformation from Keplerian to Cartesian coordinates is _not_ the inverse of the transformation from Cartesian to Keplerian coordinates!
48+
:::
49+
50+
```{julia}
51+
cartesian_to_keplerian(c..., μ)
52+
```
53+
54+
## Energy Calculations
55+
56+
Every (restricted) orbit has an associated specific energy: the energy of the orbit per unit mass.
57+
An associated parameter is the $C_3$ energy, which is defined as $v^2 - \frac{2\mu}{r}$, where $v$ and $r$ are the scalar instantaneous orbital speed and radius values respectively.
58+
59+
```{julia}
60+
specific_energy(c..., μ)
61+
```
62+
63+
```{julia}
64+
c3(c..., μ)
65+
```
66+
67+
The specific potential energy includes the potential energy per unit mass.
68+
Of course, the velocity components of the Cartesian state are not relevant to the calculation!
69+
For convenience, you can still provide the full Cartesian state in the method: the calculation will simply discard the velocity components.
70+
71+
```{julia}
72+
P = specific_potential_energy(c..., μ)
73+
```
74+
75+
```{julia}
76+
@assert P == specific_potential_energy(norm([c.x, c.y, c.z]), μ)
77+
```
78+
79+
## Orbital Characterizations
80+
81+
Simple characterizations, such as the instantaneous orbital speed, orbital radius, or semi-parameter, are also available.
82+
83+
```{julia}
84+
r = orbital_radius(c..., μ)
85+
```
86+
87+
```{julia}
88+
v = orbital_speed(c..., μ)
89+
```
90+
91+
```{julia}
92+
p = semi_parameter(c..., μ)
93+
```
94+
95+
:::{.callout-tip appearance="simple"}
96+
For circular orbits, the semi-parameter $p$ is equivalent to the orbital radius $r$!
97+
:::
98+
99+
## Next Steps
100+
101+
Circular orbits are quite simple problems to solve; they are a special case of Keplerian orbits in general.
102+
The following usage example presents non-circular Keplerian orbits, and the additional calculations that are relevant to such problems, e.g. eccentricity, the periapsis radius, and the apoapsis radius.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
number-depth: 2
3+
---
4+
5+
# Examples
6+
7+
_Usage examples for `AstrodynamicalCalculations`._
8+
9+
All following subsections show how various astrodynamics calculations can be performed using `AstrodynamicalCalculations`.
10+
As mentioned previously, you can install `AstrodynamicalCalculations` using one of the lines below.
11+
12+
```julia
13+
import Pkg
14+
Pkg.add("AstrodynamicalCalculations")
15+
```
16+
17+
```julia
18+
pkg> add AstrodynamicalCalculations
19+
```

0 commit comments

Comments
 (0)