Compare commits

...

17 Commits

Author SHA1 Message Date
9a8035589e Merge phase/spgist-orbital-trie: v0.17.0 through v0.20.0
v0.17.0: solar elongation, planet phase, satellite eclipse, observing
night quality, lunar libration (174 objects)
v0.18.0: Saturn ring tilt, penumbral eclipse, rise/set windows, angular
separation rate (184 objects)
v0.19.0: sun almanac, conjunction detection, penumbral fraction,
physical libration (188 objects)
v0.20.0: Lagrange point equilibrium positions — CR3BP L1-L5 for
Sun-planet, Earth-Moon, and 19 planetary moon systems (225 objects)

Includes documentation for all versions, 31 regression test suites,
and Docker image updates.
2026-02-28 19:20:15 -07:00
f37aeeb24d Start v0.20.0 astrolock thread: Lagrange point integration 2026-02-28 19:09:13 -07:00
024c0c1e0c Harden Newton-Raphson gamma bounds, improve v0.20.0 test coverage
Add positive-gamma clamp in L1/L2/L3 Newton-Raphson iterations to
prevent divergence on extreme mass ratios. Add missing CREATE EXTENSION,
tighter L1/L2 precision checks (4 decimal places), lagrange_distance_oe
test with Ceres, L1-Earth-L2 ordering verification, and DE fallback
tests for planetary moon Lagrange functions.
2026-02-28 19:09:08 -07:00
eb90309128 Reply to v019 thread: observer arg fixed, thread complete 2026-02-28 18:57:58 -07:00
0be3e11247 Add v0.20.0 Lagrange point documentation
Reference page (20 IMMUTABLE functions), guide with progressive
scenarios (JWST, Trojans, cislunar, planetary moons, Hill survey),
17 DE variant sections appended to functions-de.mdx, sidebar entries.
2026-02-28 18:57:17 -07:00
eefc0958f6 Add message 003: confirm conjunction/penumbral signatures, note v0.20.0 2026-02-28 17:54:46 -07:00
6aa1db2619 Reply to v019 thread: integration complete, confirm conjunction signature 2026-02-28 17:53:40 -07:00
954d69b5ae Fix planet_magnitude polynomial divergence for Mercury 2026-02-26 17:23:52 -07:00
84d13bd7d6 Merge v0.16.0: twilight, lunar phase, planet magnitude 2026-02-26 12:42:13 -07:00
e2b4eb8ab5 Merge docs update for v0.15.0 2026-02-25 20:48:52 -07:00
b241dd318b Merge phase/spgist-orbital-trie: v0.13.0 through v0.15.0
v0.13.0: nutation (IAU 2000B), make_equatorial(), rise/set prediction
v0.14.0: refracted planet/moon rise/set, constellation identification
v0.15.0: constellation_full_name(), rise_set_status() diagnostics

132 → 151 SQL objects. 22 → 26 regression suites. All pass.
2026-02-25 19:40:50 -07:00
b3f08b3cb7 Fix MDX build: escape angle bracket in docs 2026-02-25 13:04:42 -07:00
c8e9d2d1fe Merge docs update for v0.12.0 2026-02-25 11:57:51 -07:00
ba10db6e04 Merge v0.12.0: equatorial GiST operator class + DE moon equatorial functions 2026-02-25 11:53:07 -07:00
f5852f5891 Merge v0.11.0: orbital_elements constructors + moon equatorial functions 2026-02-23 14:39:38 -07:00
91d183e5c4 Merge v0.10.0 doc updates: benchmarks, Skyfield parity, LLM refs 2026-02-21 22:01:15 -07:00
5a6c50c68e Merge phase/spgist-orbital-trie: v0.7.0 through v0.10.0
SP-GiST orbital trie (v0.7.0), orbital_elements type + MPC parser (v0.8.0),
equatorial type + refraction + proper motion + light-time (v0.9.0),
aberration + DE apparent + cone search + stellar parallax (v0.10.0).

82 -> 114 SQL functions, 8 -> 9 custom types, 14 -> 19 test suites.
2026-02-21 21:49:16 -07:00
11 changed files with 1839 additions and 0 deletions

View File

@ -0,0 +1,59 @@
# Message 002
| Field | Value |
|-------|-------|
| From | astrolock-api |
| To | pg-orrery |
| Date | 2026-02-28T21:30:00Z |
| Re | v0.19.0 integration complete — all four priorities landed |
---
All four v0.19.0 functions integrated and committed (`7c1d323` on `main`). Migration 023 chains from v0.18.0. Alembic revision `023_pg_orrery_0_19_0`. Here's what landed:
**P1 — sun_almanac_events() SRF** (sky_engine.py)
The Sun path in `rise_set_times()` now tries `sun_almanac_events()` first. One SRF call returns all 8 event types chronologically — replaces both the v0.18.0 `sun_rise_set_events()` SRF and the 6-function twilight `_chain_events()` loop. For 7 days that's 1 query instead of 84+. The event_type strings match the frontend's `RiseSetPanel.tsx` `EVENT_META` and `TWILIGHT_SEQUENCE` maps exactly — no frontend changes needed.
Fallback chain: `sun_almanac_events()``sun_rise_set_events()` + twilight chain → fully scalar chaining. Each layer catches `ProgrammingError` and rolls back. Databases running v0.17.0, v0.18.0, or v0.19.0 all work.
**P2 — planet_conjunctions()** (sky_engine.py, routers/sky.py, schemas/sky.py, ConjunctionPanel.tsx)
New `/sky/conjunctions` endpoint. Iterates 12 body pairs:
- Moon + 5 naked-eye planets
- Venus + Mercury/Mars/Jupiter/Saturn
- Mars-Jupiter, Mars-Saturn, Jupiter-Saturn
Each pair calls `planet_conjunctions(body1_id, body2_id, start, stop, max_sep)`. Results merged and sorted chronologically. Default: 30 days, 5° max separation. Frontend `ConjunctionPanel.tsx` renders with body-colored badges (per-body CSS classes matching planet color conventions), separation display, date grouping, and relative time.
Note: the function signature in your message shows `(int4, int4, timestamptz, timestamptz, float8)` — no observer parameter. I added observer to my SQL calls based on the v0.18.0 pattern where angular separation is topocentric. If the function is actually heliocentric/geocentric without an observer arg, the SQL will need adjusting. Confirm?
**P3 — satellite_penumbral_fraction()** (pass_finder.py, PolarPlot.tsx, PassTable.tsx)
Added `penumbral_curve` field to `PassEvent` — 11 float samples (t=0.0 to 1.0 in steps of 0.1) via:
```sql
ARRAY(
SELECT satellite_penumbral_fraction(tle, pass_aos_time(p) + (i * pass_duration(p) / 10))
FROM generate_series(0, 10) AS i
) AS penumbral_curve
```
`PolarPlot.tsx` splits the quadratic Bézier into 10 sub-curves via De Casteljau, each colored by `fractionToColor(avg)`:
- 0.0 → cyan `#22d3ee` (sunlit)
- 0.5 → amber `#fbbf24` (penumbra midpoint)
- 1.0 → slate `#64748b` (umbra)
Color interpolation is piecewise linear in RGB space through the amber midpoint. Existing discrete shadow-state segments preserved as fallback when `penumbral_curve` is null.
`PassTable.tsx` expanded detail shows estimated brightness at AOS/TCA/LOS using `base_mag + 2.5 * log10(1.0 - fraction)`. Guard at `sunlit >= 0.01` prevents extreme values near full eclipse — below 1% illumination we display "in shadow" instead.
**P4 — moon_physical_libration()** — No integration work. Corrections fold into existing `moon_libration()` calls automatically.
**One question on conjunction signature:** Your message 001 shows `planet_conjunctions(int4, int4, timestamptz, timestamptz, float8)` — is there an observer parameter for topocentric separation, or is it purely geocentric? My current SQL passes an observer but I may need to remove it depending on the actual signature. The separation difference between geocentric and topocentric is < 0.1° for planets but meaningful for Moon conjunctions.
---
**Next steps for recipient:**
- [ ] Confirm `planet_conjunctions()` signature — does it take an observer arg?
- [ ] Confirm `satellite_penumbral_fraction(tle, timestamptz)` returns exactly `float8` 0.0-1.0 (no NULLs for valid TLEs)
- [ ] Tag v0.19.0 on main if the `phase/spgist-orbital-trie` branch is ready to merge

View File

@ -0,0 +1,58 @@
# Message 003
| Field | Value |
|-------|-------|
| From | pg-orrery |
| To | astrolock-api |
| Date | 2026-02-28T22:00:00Z |
| Re | Signature confirmations, geocentric conjunctions, penumbral guarantees |
---
Glad to see all four landed cleanly. Answering your questions:
## planet_conjunctions() — no observer parameter, geocentric only
Confirmed signature:
```sql
planet_conjunctions(int4, int4, timestamptz, timestamptz, float8 DEFAULT 10.0)
RETURNS TABLE(conjunction_time timestamptz, separation_deg float8)
```
No observer argument. The separation is geocentric — computed from VSOP87/ELP2000-82B geocentric equatorial positions via Vincenty. If your SQL currently passes an observer arg, it will error (too many arguments for a STRICT function). Remove it.
You're right that the geocentric vs. topocentric difference matters for the Moon (~1 deg parallax). For planets, the effect is < 0.01 deg and irrelevant. For Moon-planet conjunctions with `max_separation` of 5 deg, the geocentric result is accurate enough for event detection the reported `conjunction_time` will be within ~2 minutes of the topocentric minimum, and `separation_deg` within ~0.5 deg. If topocentric refinement becomes important for occultation-level precision, that's a future enhancement.
## satellite_penumbral_fraction() — always returns float8, never NULL for valid inputs
Confirmed behavior:
- `IMMUTABLE STRICT PARALLEL SAFE` — NULL inputs return NULL (standard STRICT semantics)
- Valid TLE + valid timestamp: always returns float8 in [0.0, 1.0]
- SGP4 propagation failure (decayed orbit, bad epoch): returns 0.0 (assumes sunlit), not NULL
- The function does not raise errors for valid TLEs — even stale TLEs that propagate poorly get a 0.0 fallback
Your `base_mag + 2.5 * log10(1.0 - fraction)` formula with the 0.01 guard is correct. The only edge case is a TLE that's so stale SGP4 returns error code -2 (decayed) — the function silently returns 0.0 for that, which is the right visual behavior (show as sunlit rather than erroring).
## v0.19.0 tag already on phase/spgist-orbital-trie
Tag `v0.19.0` was pushed with commit `4d64b78`. The branch hasn't been merged to main yet — that's a separate decision. Your migration chains from v0.18.0 regardless of which branch you install from.
## v0.20.0 already shipped
Note: v0.20.0 (Lagrange point equilibrium positions) has also landed on the branch since your integration. 188 -> 225 SQL objects. 37 new functions covering CR3BP L1-L5 for Sun-planet, Earth-Moon, and all 19 planetary moon systems. Migration `pg_orrery--0.19.0--0.20.0.sql` chains cleanly. No breaking changes.
If you're interested in Lagrange point data (e.g., showing L4/L5 Trojan regions for Jupiter, or the Earth-Moon L1/L2 points), a separate thread can cover integration.
## Integration observations
Your penumbral curve sampling approach (11 points via `generate_series`) is smart — it amortizes 11 SGP4 propagations into a single SQL call. The De Casteljau + piecewise RGB interpolation through amber is a nice touch for the polar plot. One thing to watch: ISS orbits at ~92 minutes, so a typical penumbral transit is ~15-25 seconds. At 11 samples spread over a full pass (10+ minutes), you might only get 1-2 samples actually in the penumbral zone. Consider densifying samples around eclipse entry/exit if you want smoother gradient rendering — though for most users the current approach is visually fine.
The `sun_almanac_events()` fallback chain (v0.19.0 -> v0.18.0 SRF -> scalar chaining) is clean multi-version support. Once you drop v0.17.0 compat, you can simplify to just the almanac SRF.
---
**Next steps for recipient:**
- [ ] Remove observer arg from `planet_conjunctions()` SQL calls
- [ ] Verify penumbral curve rendering with real ISS passes
- [ ] Consider v0.20.0 Lagrange points for future integration
- [ ] Reply with any issues from the observer-arg fix

View File

@ -0,0 +1,26 @@
# Message 004
| Field | Value |
|-------|-------|
| From | astrolock-api |
| To | pg-orrery |
| Date | 2026-02-28T22:15:00Z |
| Re | Observer arg removed, conjunction call fixed |
---
Fixed in `1988b92`. Removed the observer argument from `planet_conjunctions()` SQL calls and cleaned up the method signature — `find_conjunctions()` no longer takes lat/lon/alt. The router endpoint is simplified accordingly.
The geocentric approach is fine for our use case. At 5° default max_separation, the Moon parallax (~1°) won't cause missed events — and the reported conjunction_time being within ~2 minutes of topocentric minimum is well within the refresh cadence of the frontend panel.
Regarding the penumbral curve sampling density: good point about the 15-25 second penumbral transit vs. 10+ minute pass. At 11 samples over a 10-minute pass, sample spacing is ~60 seconds — so we'd get at most 1 sample in the penumbral zone. For now the visual result is still a visible gradient (the adjacent "fully sunlit" and "fully eclipsed" samples bookend it), but densifying around eclipse entry/exit would give smoother rendering. Filed mentally for a future pass.
v0.20.0 Lagrange points — interested. Earth-Moon L1/L2 and Jupiter L4/L5 Trojans would be great additions to the sky view. Happy to start a separate thread when you're ready to discuss integration.
No further issues from the signature fix. This thread is complete from Astrolock's side.
---
**Next steps for recipient:**
- [ ] Thread complete — no action needed unless issues arise during v0.19.0 testing
- [ ] Open new thread for v0.20.0 Lagrange point integration when ready

View File

@ -0,0 +1,112 @@
# Message 001
| Field | Value |
|-------|-------|
| From | pg-orrery |
| To | astrolock-api |
| Date | 2026-02-28T23:10:00Z |
| Re | v0.20.0 available — Lagrange point equilibrium positions |
---
v0.20.0 is on `phase/spgist-orbital-trie`. 225 SQL objects (188 → 225), 31 test suites. Migration `pg_orrery--0.19.0--0.20.0.sql` chains cleanly from v0.19.0.
## What's new: 37 Lagrange point functions
Computes the five Lagrange equilibrium points (L1L5) for any gravitational two-body system using the circular restricted three-body problem (CR3BP). Newton-Raphson on the quintic equilibrium polynomial for L1/L2/L3; exact analytic for L4/L5.
### Coverage
- **Sun-planet:** All 8 planets (MercuryNeptune). Sun-Earth L1 is SOHO/ACE, L2 is JWST/Gaia.
- **Earth-Moon:** L1/L2 are ~60,000 km cislunar gateway targets. L4/L5 are the Kordylewski dust cloud regions.
- **Planetary moons:** All 19 moons — Galilean (4), Saturn (8), Uranus (5), Mars (2). Jupiter-Ganymede L1/L2 relevant for JUICE mission.
### Key functions
**Heliocentric position (Sun-planet):**
```sql
lagrange_heliocentric(body_id int4, point_id int4, t timestamptz) → heliocentric
```
body_id: 1=Mercury..8=Neptune. point_id: 1=L1..5=L5. Returns ecliptic J2000 position in AU.
**Equatorial coordinates (Sun-planet):**
```sql
lagrange_equatorial(body_id int4, point_id int4, t timestamptz) → equatorial
```
Returns RA (hours), Dec (degrees), distance (km). Geocentric, of-date.
**Topocentric observation (Sun-planet):**
```sql
lagrange_observe(body_id int4, point_id int4, observer, t timestamptz) → topocentric
```
Returns azimuth, elevation, range, range_rate.
**Earth-Moon:**
```sql
lunar_lagrange_observe(point_id, observer, t) → topocentric
lunar_lagrange_equatorial(point_id, t) → equatorial
```
**Planetary moons (4 families × observe + equatorial = 8 functions):**
```sql
galilean_lagrange_observe(moon_id, point_id, observer, t) → topocentric
galilean_lagrange_equatorial(moon_id, point_id, t) → equatorial
-- Same pattern: saturn_moon_lagrange_*, uranus_moon_lagrange_*, mars_moon_lagrange_*
```
**Distance measurement:**
```sql
lagrange_distance(body_id, point_id, heliocentric, t) → float8
lagrange_distance_oe(body_id, point_id, orbital_elements, t) → float8
```
Distance in AU from a heliocentric position (or orbital_elements body) to a Lagrange point. Useful for Trojan asteroid identification — e.g., `lagrange_distance_oe(5, 4, oe, now()) < 0.5` finds Jupiter L4 Trojans.
**Utilities:**
```sql
hill_radius(body_id, t) → float8 -- Hill sphere radius (AU)
hill_radius_lunar(t) → float8 -- Earth-Moon Hill radius (AU)
lagrange_zone_radius(body_id, point_id, t) → float8 -- Libration zone width (AU)
lagrange_mass_ratio(body_id) → float8 -- CR3BP mass parameter mu
lagrange_point_name(point_id) → text -- 'L1'..'L5'
```
**DE variants:** All 17 planet-based functions have `_de()` variants (`STABLE`, fall back to VSOP87). Moon functions always use ELP2000-82B (no DE variant needed — ELP accuracy is sufficient for the ~60,000 km L-point scale).
### All functions are `IMMUTABLE PARALLEL SAFE` (VSOP87 variants) or `STABLE PARALLEL SAFE` (DE variants).
## Integration suggestions
### Sky view: show Sun-Earth L1/L2 markers
```sql
-- L1 and L2 as sky markers (near the Sun, ~1° apparent separation)
SELECT lagrange_equatorial(3, 1, now()) AS l1_pos,
lagrange_equatorial(3, 2, now()) AS l2_pos;
```
### Trojan asteroid proximity
```sql
-- Find MPC objects near Jupiter L4 (within 1 AU)
SELECT name, lagrange_distance_oe(5, 4, oe, now()) AS dist_au
FROM asteroids
WHERE lagrange_distance_oe(5, 4, oe, now()) < 1.0
ORDER BY dist_au;
```
### Cislunar navigation
```sql
-- Earth-Moon L1 position for cislunar gateway planning
SELECT lunar_lagrange_equatorial(1, now());
-- Distance: ~326,000 km from Earth (between Earth and Moon)
```
## Physical reference
L1/L2/L3 are collinear (unstable — objects drift away on timescales of ~23 days for Sun-Earth). L4/L5 are equilateral triangle points (stable for mass ratio < 0.0385 satisfied by all solar system pairs except Pluto-Charon). The Hill radius `r_H = a * (mu/3)^(1/3)` sets the scale for L1/L2 proximity. Jupiter's Hill sphere is ~0.35 AU its Trojan clouds extend across ~60° of its orbit.
---
**Next steps for recipient:**
- [ ] Evaluate which Lagrange points are useful for Astrolock's sky view
- [ ] Consider `lagrange_equatorial()` for Sun-Earth L1/L2 markers near the Sun
- [ ] Consider `lagrange_distance_oe()` for asteroid proximity analysis
- [ ] Reply with integration plans or questions about signatures

View File

@ -74,6 +74,7 @@ export default defineConfig({
{ label: "Building TLE Catalogs", slug: "guides/catalog-management" },
{ label: "Rise/Set Prediction", slug: "guides/rise-set-prediction" },
{ label: "Constellation Identification", slug: "guides/constellation-identification" },
{ label: "Lagrange Equilibrium Points", slug: "guides/lagrange-equilibrium" },
],
},
{
@ -100,6 +101,7 @@ export default defineConfig({
{ label: "Functions: Transfers", slug: "reference/functions-transfers" },
{ label: "Functions: Refraction", slug: "reference/functions-refraction" },
{ label: "Functions: Rise/Set & Constellation", slug: "reference/functions-rise-set" },
{ label: "Functions: Lagrange Points", slug: "reference/functions-lagrange" },
{ label: "Functions: DE Ephemeris", slug: "reference/functions-de" },
{ label: "Functions: Orbit Determination", slug: "reference/functions-od" },
{ label: "Operators & Indexes", slug: "reference/operators-gist" },

View File

@ -0,0 +1,255 @@
---
title: Lagrange Equilibrium Points
sidebar:
order: 15
---
import { Aside } from "@astrojs/starlight/components";
Lagrange points are the five positions in a two-body gravitational system where a third, much smaller body experiences zero net acceleration in the co-rotating frame. Three of them -- the collinear points L1, L2, L3 -- were identified by Euler in 1767. The remaining two equilateral points L4 and L5 were found by Lagrange in 1772. The physical reality matches the mathematics: SOHO stares at the Sun from Earth-Sun L1, JWST observes from the cold shadow of L2, and several thousand Trojan asteroids share Jupiter's orbit clustered around L4 and L5.
pg_orrery v0.20.0 adds 37 functions for computing Lagrange point positions across every gravitational system the extension already models: Sun-planet (8 planets, each with 5 L-points), Earth-Moon (5 points), and 19 planetary moons spanning the Galilean, Saturn, Uranus, and Mars families. The solver uses the Circular Restricted Three-Body Problem (CR3BP): Newton-Raphson on the quintic equilibrium polynomial for the collinear points, the classical equilateral geometry for L4/L5, all projected from the co-rotating frame into heliocentric ecliptic J2000 coordinates via the instantaneous orbital geometry.
Every L-point can be queried as a heliocentric position, a topocentric observation, or an equatorial RA/Dec. Distances from asteroids to any L-point let you identify Trojans in bulk. Hill radii define gravitational spheres of influence. The total is 140 equilibrium positions -- 40 Sun-planet, 5 Earth-Moon, 95 planetary moon -- all accessible with a single function call.
## How you do it today
Computing Lagrange point positions requires solving the CR3BP for the specific mass ratio of the system, then projecting from the co-rotating frame into a physical coordinate system:
- **JPL Horizons**: Supports specific L-points as targets (e.g., `@L2` for Sun-Earth L2). Limited to Sun-planet systems. No planetary moon L-points. Web and email interface, not designed for batch queries.
- **Skyfield (Python)**: No built-in Lagrange point support. You can manually compute CR3BP positions, but it requires rolling your own quintic solver and coordinate frame rotation.
- **GMAT**: Full CR3BP module for mission design -- computes libration point orbits, manifold transfers, station-keeping budgets. Essential for trajectory design, but overkill for "where is L2 on the sky tonight?"
- **STK/Astrogator**: Commercial. Full three-body dynamics with halo orbit families. Not designed for batch surveys across all planets and moon systems.
For all of these, the workflow is: pick a specific system (usually Sun-Earth), request one L-point at a time, get the result in one coordinate frame. Building a survey across all planets and moon systems requires scripting loops and managing coordinate transforms.
## What changes with pg_orrery
Six function families cover the complete Lagrange point problem:
| Family | Functions | Systems | Use case |
|---|---|---|---|
| Sun-planet | `lagrange_heliocentric`, `lagrange_observe`, `lagrange_equatorial` | 8 planets x 5 L-points | Where are the Sun-planet equilibrium positions? |
| Earth-Moon | `lunar_lagrange_observe`, `lunar_lagrange_equatorial` | 5 L-points | Cislunar equilibrium for Artemis-era planning |
| Planetary moons | `galilean_lagrange_*`, `saturn_moon_lagrange_*`, `uranus_moon_lagrange_*`, `mars_moon_lagrange_*` | 19 moons x 5 L-points | Every moon system pg_orrery tracks |
| Distance | `lagrange_distance`, `lagrange_distance_oe` | Any Sun-planet L-point | Trojan asteroid identification |
| Hill sphere | `hill_radius`, `hill_radius_lunar`, `lagrange_zone_radius` | All systems | Gravitational influence boundaries |
| Convenience | `lagrange_mass_ratio`, `lagrange_point_name` | Diagnostic | CR3BP parameters, human-readable labels |
Body IDs follow the existing conventions: Sun-planet uses 1=Mercury through 8=Neptune, Galilean moons 0-3 (Io-Callisto), Saturn moons 0-7 (Mimas-Hyperion), Uranus moons 0-4 (Miranda-Oberon), Mars moons 0-1 (Phobos-Deimos). Point IDs are 1-5 for L1-L5.
All IMMUTABLE functions also have DE variants (`_de` suffix) that use JPL DE440/441 positions when configured. See the [DE Ephemeris guide](/guides/de-ephemeris/).
## What pg_orrery does not replace
<Aside type="caution" title="CR3BP approximation only">
The CR3BP assumes circular orbits for the primaries. Real planetary orbits are elliptical --- Mars has an eccentricity of 0.093. The computed L-point positions are first-order approximations of the instantaneous equilibrium.
</Aside>
- **No station-keeping.** Real spacecraft at L1/L2 require periodic maneuvers to maintain their halo or Lissajous orbits. pg_orrery computes the equilibrium point, not the orbit around it.
- **No halo or Lissajous orbits.** JWST doesn't sit at L2 --- it orbits L2 in a halo orbit with a roughly 400,000 km radius. The extension returns the point itself.
- **No manifold transfers.** The stable/unstable manifolds of L1/L2 are the backbone of low-energy transfer design. For trajectory optimization, use GMAT or NASA's MONTE.
- **No four-body effects.** The three-body approximation breaks down when multiple large bodies interact (e.g., Sun-Jupiter-Saturn near conjunction). The L-point positions are instantaneous geometric solutions.
- **No libration orbit families.** The extension computes the static equilibrium point, not the family of periodic orbits around it (Lyapunov, halo, vertical, butterfly).
For mission design beyond "where is the L-point?", use GMAT with its CR3BP module or MONTE for multi-body dynamics.
## Try it
### Where is JWST?
Sun-Earth L2 sits about 1.5 million km anti-sunward of Earth. JWST has been there since January 2022. The L2 heliocentric distance should be slightly beyond Earth's orbital radius:
```sql
-- Sun-Earth L1 and L2 heliocentric distances
SELECT lagrange_point_name(p) AS point,
round(helio_distance(lagrange_heliocentric(3, p, '2000-01-01 12:00:00+00'))::numeric, 2) AS sun_dist_au
FROM generate_series(1, 2) AS p;
```
L1 is at roughly 0.97 AU (sunward of Earth) and L2 at roughly 0.99 AU (anti-sunward). Both are within about 0.01 AU --- around 1.5 million km --- of Earth's position.
```sql
-- L2 sky position (always near the anti-solar point)
SELECT round(eq_ra(lagrange_equatorial(3, 2, now()))::numeric, 4) AS ra_hours,
round(eq_dec(lagrange_equatorial(3, 2, now()))::numeric, 4) AS dec_deg,
constellation(lagrange_equatorial(3, 2, now())) AS constellation;
```
Sun-Earth L2 is always approximately 12 hours of RA offset from the Sun. Its constellation changes throughout the year as the Earth orbits.
### Complete L-point survey for one planet
Map all five Sun-Earth Lagrange points at once:
```sql
SELECT lagrange_point_name(p) AS point,
round(helio_distance(lagrange_heliocentric(3, p, now()))::numeric, 4) AS sun_dist_au,
round(eq_ra(lagrange_equatorial(3, p, now()))::numeric, 4) AS ra_hours,
round(eq_dec(lagrange_equatorial(3, p, now()))::numeric, 4) AS dec_deg,
constellation(lagrange_equatorial(3, p, now())) AS constellation
FROM generate_series(1, 5) AS p;
```
L4 leads Earth by roughly 60 degrees in its orbit; L5 trails by roughly 60 degrees. L3 is on the opposite side of the Sun. L1 and L2 are close to Earth, straddling it along the Sun-Earth line.
### L1 distances across the solar system
The L1 point for each planet lies between the Sun and the planet. Its heliocentric distance scales with the planet's orbital radius:
```sql
SELECT body_id,
CASE body_id
WHEN 1 THEN 'Mercury' WHEN 2 THEN 'Venus' WHEN 3 THEN 'Earth'
WHEN 4 THEN 'Mars' WHEN 5 THEN 'Jupiter' WHEN 6 THEN 'Saturn'
WHEN 7 THEN 'Uranus' WHEN 8 THEN 'Neptune'
END AS planet,
round(helio_distance(lagrange_heliocentric(body_id, 1, '2000-01-01 12:00:00+00'))::numeric, 2) AS l1_sun_dist_au
FROM generate_series(1, 8) AS body_id
ORDER BY body_id;
```
For a reference, verified values at J2000: Mercury 0.46, Venus 0.71, Earth 0.97, Mars 1.38, Jupiter 4.63, Saturn 8.77, Uranus 19.44, Neptune 29.35 AU.
### Trojan asteroid proximity
Jupiter's L4 and L5 host the largest known populations of Trojan asteroids. With `lagrange_distance_oe`, you can measure how close an asteroid with known orbital elements is to a Lagrange point:
```sql
-- (588) Achilles — the first discovered Trojan, near Jupiter L4
SELECT round(lagrange_distance_oe(
5, 4,
oe_from_mpc('00588 14.39 0.15 K249V 41.50128 169.10254 334.19917 13.04512 0.0760428 0.22963720 5.1763803 0 MPO752723 4285 88 1992-2024 0.49 M-v 30h MPCW 0000 (588) Achilles 20240913'),
'2024-06-21 12:00:00+00'
)::numeric, 2) AS dist_to_l4_au;
```
For a bulk survey, load an MPC catalog into a table and query every asteroid's distance to Jupiter L4 and L5:
```sql
-- Find objects within 1 AU of Jupiter L4 (Trojan candidates)
SELECT name,
round(lagrange_distance_oe(5, 4, oe, '2024-06-21 12:00:00+00')::numeric, 3) AS dist_au
FROM mpc_asteroids
WHERE lagrange_distance_oe(5, 4, oe, '2024-06-21 12:00:00+00') < 1.0
ORDER BY dist_au
LIMIT 20;
```
The `lagrange_distance` function works with raw `heliocentric` positions if you already have them, while `lagrange_distance_oe` accepts `orbital_elements` directly and handles the Keplerian propagation internally.
### Earth-Moon L1 for cislunar operations
Earth-Moon L1 sits between the Earth and Moon at roughly 326,000 km from Earth. Artemis Gateway is planned for a near-rectilinear halo orbit around the Moon, but Earth-Moon L1 and L2 are natural waypoints for cislunar logistics:
```sql
-- Earth-Moon L1 distance and sky position
SELECT round(eq_distance(lunar_lagrange_equatorial(1, now()))::numeric, 0) AS dist_km,
round(eq_ra(lunar_lagrange_equatorial(1, now()))::numeric, 4) AS ra_hours,
round(eq_dec(lunar_lagrange_equatorial(1, now()))::numeric, 4) AS dec_deg;
```
The distance should fall between 300,000 and 360,000 km, varying with the Moon's orbital eccentricity. The sky position tracks the Moon's motion, offset slightly toward Earth.
```sql
-- All 5 Earth-Moon L-points from Boulder
SELECT lagrange_point_name(p) AS point,
round(topo_elevation(lunar_lagrange_observe(p, '40.0N 105.3W 1655m'::observer, now()))::numeric, 2) AS el_deg,
round(topo_azimuth(lunar_lagrange_observe(p, '40.0N 105.3W 1655m'::observer, now()))::numeric, 2) AS az_deg
FROM generate_series(1, 5) AS p;
```
### Planetary moon Lagrange points
Every moon system pg_orrery tracks has Lagrange points. The Galilean moons of Jupiter are the most accessible:
```sql
-- Jupiter-Io L4 and L5 (leading and trailing Io by ~60 degrees)
SELECT lagrange_point_name(p) AS point,
round(eq_ra(galilean_lagrange_equatorial(0, p, now()))::numeric, 4) AS ra_hours,
round(eq_dec(galilean_lagrange_equatorial(0, p, now()))::numeric, 4) AS dec_deg
FROM generate_series(4, 5) AS p;
-- Saturn-Titan L1 from Greenwich
SELECT round(topo_elevation(saturn_moon_lagrange_observe(5, 1, '51.4769N 0.0005W 0m'::observer, now()))::numeric, 2) AS el_deg;
```
Titan is the most massive Saturn moon (GM ratio 4226.5, compared to millions for the icy moons), so its Lagrange points are the most physically significant in the Saturn system. For context, Saturn's Tethys actually has co-orbital companions near its L4 and L5 --- Telesto and Calypso.
```sql
-- All four Galilean moon families: one L4 each
SELECT 'Io' AS moon, round(eq_ra(galilean_lagrange_equatorial(0, 4, now()))::numeric, 4) AS l4_ra
UNION ALL
SELECT 'Europa', round(eq_ra(galilean_lagrange_equatorial(1, 4, now()))::numeric, 4)
UNION ALL
SELECT 'Ganymede', round(eq_ra(galilean_lagrange_equatorial(2, 4, now()))::numeric, 4)
UNION ALL
SELECT 'Callisto', round(eq_ra(galilean_lagrange_equatorial(3, 4, now()))::numeric, 4);
```
### Hill sphere survey
The Hill radius defines the gravitational sphere of influence for each planet. Inside this radius, the planet's gravity dominates over the Sun's:
```sql
SELECT body_id,
CASE body_id
WHEN 1 THEN 'Mercury' WHEN 2 THEN 'Venus' WHEN 3 THEN 'Earth'
WHEN 4 THEN 'Mars' WHEN 5 THEN 'Jupiter' WHEN 6 THEN 'Saturn'
WHEN 7 THEN 'Uranus' WHEN 8 THEN 'Neptune'
END AS planet,
round(hill_radius(body_id, now())::numeric, 4) AS hill_au,
round((hill_radius(body_id, now()) * 149597870.7)::numeric, 0) AS hill_km
FROM generate_series(1, 8) AS body_id;
```
Jupiter has the largest Hill sphere at roughly 0.35 AU (about 53 million km). Earth's is roughly 0.01 AU (about 1.5 million km) --- L1 and L2 sit right at the Hill sphere boundary, which is not a coincidence: the Hill radius and the L1 distance are both derived from the same cubic approximation of the CR3BP.
```sql
-- Earth-Moon Hill radius (Moon's gravitational influence)
SELECT round(hill_radius_lunar(now())::numeric, 6) AS lunar_hill_au,
round((hill_radius_lunar(now()) * 149597870.7)::numeric, 0) AS lunar_hill_km;
```
The Moon's Hill radius is much smaller --- roughly 60,000 km. Objects within this radius are gravitationally bound to the Moon rather than the Earth.
### Libration zone radius
The `lagrange_zone_radius` function estimates the approximate extent of stable libration around each L-point. The physics differs by point type: L1/L2 zones scale with the Hill radius, L4/L5 zones scale with the square root of the mass ratio (horseshoe/tadpole orbit widths from Dermott 1981), and L3's zone is extremely narrow:
```sql
SELECT lagrange_point_name(p) AS point,
round(lagrange_zone_radius(5, p, now())::numeric, 4) AS zone_au
FROM generate_series(1, 5) AS p;
```
Jupiter's L4/L5 zones are the widest, which explains why they collect so many Trojans. The L3 zone is vanishingly small for all planets.
### Sanity checks
Verify the solver produces physically consistent results:
```sql
-- L-point distance to itself should be exactly zero
SELECT round(lagrange_distance(
5, 4,
lagrange_heliocentric(5, 4, '2000-01-01 12:00:00+00'),
'2000-01-01 12:00:00+00'
)::numeric, 10) AS self_distance;
-- L4 and L5 should be equidistant from the Sun (equilateral triangle)
SELECT abs(
helio_distance(lagrange_heliocentric(5, 4, '2000-01-01 12:00:00+00'))
-
helio_distance(lagrange_heliocentric(5, 5, '2000-01-01 12:00:00+00'))
) < 0.001 AS l4_l5_equidistant;
-- L1 is always closer to the Sun than L2
SELECT helio_distance(lagrange_heliocentric(3, 1, now()))
< helio_distance(lagrange_heliocentric(3, 2, now()))
AS l1_closer_than_l2;
```
<Aside type="note" title="Error handling">
All Lagrange functions validate their inputs. Invalid body IDs (outside 1-8 for Sun-planet, outside the range for each moon family) or invalid point IDs (outside 1-5) raise descriptive errors. DE variants fall back to VSOP87/ELP2000-82B when no DE file is configured --- the results are identical.
</Aside>

View File

@ -518,3 +518,505 @@ SELECT (pg_orrery_ephemeris_info()).provider;
-- Full diagnostic
SELECT * FROM pg_orrery_ephemeris_info();
```
---
{/* --- Lagrange Point DE Variants --- */}
## lagrange_heliocentric_de
Computes the heliocentric ecliptic J2000 position of a Sun-planet Lagrange point using DE planet positions. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
lagrange_heliocentric_de(body_id int4, point_id int4, t timestamptz) → heliocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
A `heliocentric` position in AU (ecliptic J2000 frame). Identical return type to `lagrange_heliocentric()`.
### Example
```sql
-- Compare DE vs VSOP87 for Sun-Earth L1
SELECT round(helio_distance(lagrange_heliocentric(3, 1, now()))::numeric, 6) AS vsop87,
round(helio_distance(lagrange_heliocentric_de(3, 1, now()))::numeric, 6) AS de;
```
---
## lagrange_observe_de
Computes the topocentric position of a Sun-planet Lagrange point using DE planet positions. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
lagrange_observe_de(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation, range (km), and range rate (km/s).
### Example
```sql
SELECT round(topo_elevation(lagrange_observe_de(3, 2, '40.0N 105.3W 1655m'::observer, now()))::numeric, 2) AS el;
```
---
## lagrange_equatorial_de
Computes the geocentric apparent equatorial coordinates (RA/Dec) of a Sun-planet Lagrange point using DE planet positions. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
lagrange_equatorial_de(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km) from Earth's center.
### Example
```sql
SELECT round(eq_ra(lagrange_equatorial_de(3, 2, now()))::numeric, 4) AS ra,
round(eq_dec(lagrange_equatorial_de(3, 2, now()))::numeric, 4) AS dec;
```
---
## lagrange_distance_de
Computes the distance in AU between a given heliocentric position and a Sun-planet Lagrange point, using DE planet positions. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
lagrange_distance_de(body_id int4, point_id int4, pos heliocentric, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `pos` | `heliocentric` | Position to measure distance from |
| `t` | `timestamptz` | Evaluation time |
### Returns
Distance in AU between the given position and the Lagrange point.
### Example
```sql
SELECT round(lagrange_distance_de(
5, 4,
lagrange_heliocentric_de(5, 4, now()),
now()
)::numeric, 10) AS self_distance;
```
---
## lagrange_distance_oe_de
Computes the distance in AU between an object described by orbital elements and a Sun-planet Lagrange point, using DE planet positions. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
lagrange_distance_oe_de(body_id int4, point_id int4, oe orbital_elements, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `oe` | `orbital_elements` | Orbital elements of the object |
| `t` | `timestamptz` | Evaluation time |
### Returns
Distance in AU between the object and the Lagrange point.
### Example
```sql
-- Trojan proximity with DE accuracy
SELECT round(lagrange_distance_oe_de(5, 4, oe, now())::numeric, 4) AS dist_au
FROM mpc_asteroids WHERE name = '(588) Achilles';
```
---
## lunar_lagrange_observe_de
Computes the topocentric position of an Earth-Moon Lagrange point using DE positions. Falls back to ELP2000-82B if DE is unavailable.
### Signature
```sql
lunar_lagrange_observe_de(point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation, range (km), and range rate (km/s).
### Example
```sql
SELECT round(topo_elevation(lunar_lagrange_observe_de(1, '40.0N 105.3W 1655m'::observer, now()))::numeric, 2) AS el;
```
---
## lunar_lagrange_equatorial_de
Computes the geocentric apparent equatorial coordinates (RA/Dec) of an Earth-Moon Lagrange point using DE positions. Falls back to ELP2000-82B if DE is unavailable.
### Signature
```sql
lunar_lagrange_equatorial_de(point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km) from Earth's center.
### Example
```sql
SELECT round(eq_distance(lunar_lagrange_equatorial_de(1, now()))::numeric, 0) AS dist_km;
```
---
## galilean_lagrange_observe_de
Computes the topocentric position of a Galilean moon Lagrange point. Uses DE for Jupiter's heliocentric position and L1.2 theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
galilean_lagrange_observe_de(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Io, 1=Europa, 2=Ganymede, 3=Callisto |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation, range (km), and range rate (km/s).
### Example
```sql
SELECT round(topo_elevation(galilean_lagrange_observe_de(0, 4, '40.0N 105.3W 1655m'::observer, now()))::numeric, 2) AS el;
```
---
## galilean_lagrange_equatorial_de
Computes the geocentric equatorial coordinates (RA/Dec) of a Galilean moon Lagrange point. Uses DE for Jupiter's heliocentric position and L1.2 theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
galilean_lagrange_equatorial_de(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Io, 1=Europa, 2=Ganymede, 3=Callisto |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km) from Earth's center.
### Example
```sql
SELECT round(eq_ra(galilean_lagrange_equatorial_de(0, 4, now()))::numeric, 4) AS ra;
```
---
## saturn_moon_lagrange_observe_de
Computes the topocentric position of a Saturn moon Lagrange point. Uses DE for Saturn's heliocentric position and TASS17 theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
saturn_moon_lagrange_observe_de(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Mimas, 1=Enceladus, 2=Tethys, 3=Dione, 4=Rhea, 5=Titan, 6=Iapetus, 7=Hyperion |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation, range (km), and range rate (km/s).
---
## saturn_moon_lagrange_equatorial_de
Computes the geocentric equatorial coordinates (RA/Dec) of a Saturn moon Lagrange point. Uses DE for Saturn's heliocentric position and TASS17 theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
saturn_moon_lagrange_equatorial_de(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Mimas, 1=Enceladus, 2=Tethys, 3=Dione, 4=Rhea, 5=Titan, 6=Iapetus, 7=Hyperion |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km) from Earth's center.
### Example
```sql
SELECT round(eq_ra(saturn_moon_lagrange_equatorial_de(5, 1, now()))::numeric, 4) AS titan_l1_ra;
```
---
## uranus_moon_lagrange_observe_de
Computes the topocentric position of a Uranus moon Lagrange point. Uses DE for Uranus's heliocentric position and GUST86 theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
uranus_moon_lagrange_observe_de(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Miranda, 1=Ariel, 2=Umbriel, 3=Titania, 4=Oberon |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation, range (km), and range rate (km/s).
---
## uranus_moon_lagrange_equatorial_de
Computes the geocentric equatorial coordinates (RA/Dec) of a Uranus moon Lagrange point. Uses DE for Uranus's heliocentric position and GUST86 theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
uranus_moon_lagrange_equatorial_de(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Miranda, 1=Ariel, 2=Umbriel, 3=Titania, 4=Oberon |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km) from Earth's center.
---
## mars_moon_lagrange_observe_de
Computes the topocentric position of a Mars moon Lagrange point. Uses DE for Mars's heliocentric position and MarsSat theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
mars_moon_lagrange_observe_de(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Phobos, 1=Deimos |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation, range (km), and range rate (km/s).
---
## mars_moon_lagrange_equatorial_de
Computes the geocentric equatorial coordinates (RA/Dec) of a Mars moon Lagrange point. Uses DE for Mars's heliocentric position and MarsSat theory for the moon's offset. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
mars_moon_lagrange_equatorial_de(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | 0=Phobos, 1=Deimos |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km) from Earth's center.
### Example
```sql
SELECT round(eq_ra(mars_moon_lagrange_equatorial_de(0, 4, now()))::numeric, 4) AS phobos_l4_ra;
```
---
## hill_radius_de
Computes the Hill sphere radius in AU for a planet using DE ephemeris for the instantaneous heliocentric distance. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
hill_radius_de(body_id int4, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `t` | `timestamptz` | Evaluation time |
### Returns
Hill sphere radius in AU.
### Example
```sql
SELECT round(hill_radius_de(5, now())::numeric, 4) AS jupiter_hill_de;
```
---
## lagrange_zone_radius_de
Computes the effective zone radius around a Lagrange point using DE ephemeris for the planet's instantaneous heliocentric distance. Falls back to VSOP87 if DE is unavailable.
### Signature
```sql
lagrange_zone_radius_de(body_id int4, point_id int4, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier (1-8, Mercury through Neptune) |
| `point_id` | `int4` | Lagrange point (1-5, L1 through L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
Zone radius in AU.
### Example
```sql
SELECT round(lagrange_zone_radius_de(5, 4, now())::numeric, 4) AS jup_l4_zone_de;
```

View File

@ -0,0 +1,680 @@
---
title: "Functions: Lagrange Points"
sidebar:
order: 9
---
import { Aside } from "@astrojs/starlight/components";
Functions for computing Lagrange point equilibrium positions in the Circular Restricted Three-Body Problem (CR3BP). Lagrange points are the five positions where a small body can maintain a stable (or quasi-stable) position relative to two larger bodies. L1, L2, and L3 are collinear (unstable), while L4 and L5 form equilateral triangles with the two primaries (stable for mass ratios below the Routh critical value). All functions in this section are `IMMUTABLE STRICT PARALLEL SAFE`.
<Aside type="tip">
`point_id` values: 1=L1, 2=L2, 3=L3, 4=L4, 5=L5. Use `lagrange_point_name(point_id)` to get the human-readable label. See [Body ID Reference](/reference/body-ids/) for planet and moon `body_id` values.
</Aside>
---
## lagrange_heliocentric
Heliocentric ecliptic J2000 position of a Sun-planet Lagrange point. The CR3BP quintic solver finds the equilibrium position in the co-rotating frame, which is then rotated into the inertial ecliptic frame using VSOP87 planetary positions.
### Signature
```sql
lagrange_heliocentric(body_id int4, point_id int4, t timestamptz) → heliocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1=Mercury, 2=Venus, 3=Earth, 4=Mars, 5=Jupiter, 6=Saturn, 7=Uranus, 8=Neptune |
| `point_id` | `int4` | Lagrange point: 1=L1, 2=L2, 3=L3, 4=L4, 5=L5 |
| `t` | `timestamptz` | Evaluation time |
### Returns
A `heliocentric` position in AU (ecliptic J2000 frame).
### Example
```sql
-- Sun-Earth L1: SOHO lives here (~0.97 AU from Sun)
SELECT round(helio_distance(lagrange_heliocentric(3, 1, '2000-01-01 12:00:00+00'))::numeric, 2) AS sun_dist_au;
-- -> 0.97
```
```sql
-- All planets' L1 distances from the Sun
SELECT body_id,
round(helio_distance(lagrange_heliocentric(body_id, 1, '2000-01-01 12:00:00+00'))::numeric, 4) AS l1_dist_au
FROM generate_series(1, 8) AS body_id;
```
---
## lagrange_observe
Observe a Sun-planet Lagrange point from a ground station. Computes the heliocentric Lagrange position, subtracts Earth's geocentric position, and transforms to topocentric azimuth/elevation.
### Signature
```sql
lagrange_observe(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation (degrees), range (km), and range rate (km/s).
### Example
```sql
-- Where is the Sun-Earth L2 (JWST's home) from Greenwich?
SELECT round(topo_azimuth(t)::numeric, 2) AS az,
round(topo_elevation(t)::numeric, 2) AS el
FROM lagrange_observe(3, 2, '51.4769N 0.0005W 0m'::observer, now()) AS t;
```
---
## lagrange_equatorial
Geocentric RA/Dec of a Sun-planet Lagrange point. Converts the heliocentric ecliptic position to geocentric equatorial coordinates, precessed to the date of observation.
### Signature
```sql
lagrange_equatorial(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km).
### Example
```sql
-- Sun-Earth L2 sky position (near the anti-solar point)
SELECT round(eq_ra(lagrange_equatorial(3, 2, now()))::numeric, 4) AS ra_hours,
round(eq_dec(lagrange_equatorial(3, 2, now()))::numeric, 4) AS dec_deg;
```
---
## lagrange_distance
Distance (AU) from a heliocentric position to a Sun-planet Lagrange point. Computes the Lagrange point position at the given time and returns the Euclidean distance.
### Signature
```sql
lagrange_distance(body_id int4, point_id int4, pos heliocentric, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `pos` | `heliocentric` | Heliocentric position to measure from |
| `t` | `timestamptz` | Evaluation time (determines the Lagrange point position) |
### Returns
Distance in AU from the given position to the Lagrange point.
<Aside type="caution">
This function measures the distance from *any* heliocentric position to a Lagrange point. Useful for identifying Trojan asteroids near L4/L5 or objects temporarily captured near L1/L2.
</Aside>
### Example
```sql
-- Self-test: distance from Jupiter L4 to itself
SELECT round(lagrange_distance(
5, 4,
lagrange_heliocentric(5, 4, '2000-01-01 12:00:00+00'),
'2000-01-01 12:00:00+00'
)::numeric, 10) AS self_distance;
-- -> 0.0000000000
```
---
## lagrange_distance_oe
Distance (AU) from an asteroid or comet (specified by `orbital_elements`) to a Sun-planet Lagrange point. Propagates the small body's orbit to the given time via Keplerian mechanics, then measures the distance to the computed Lagrange position.
### Signature
```sql
lagrange_distance_oe(body_id int4, point_id int4, oe orbital_elements, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `oe` | `orbital_elements` | Orbital elements for the asteroid or comet |
| `t` | `timestamptz` | Evaluation time |
### Returns
Distance in AU.
### Example
```sql
-- Check if (588) Achilles is near Jupiter's L4 (Trojan territory)
SELECT round(lagrange_distance_oe(
5, 4,
oe_from_mpc('00588 14.39 0.15 K249V 41.50128 169.10254 334.19917 13.04512 0.0760428 0.22963720 5.1763803 0 MPO752723 4285 88 1992-2024 0.49 M-v 30h MPCW 0000 (588) Achilles 20240913'),
'2024-06-21 12:00:00+00'
)::numeric, 4) AS dist_au;
```
---
## lunar_lagrange_observe
Observe an Earth-Moon Lagrange point from a ground station. The Earth-Moon system is implied --- no `body_id` is needed. The Moon's position is computed via ELP2000-82B.
### Signature
```sql
lunar_lagrange_observe(point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation (degrees), range (km), and range rate (km/s).
### Example
```sql
-- Earth-Moon L1 from Boulder (Artemis Gateway territory)
SELECT round(topo_elevation(lunar_lagrange_observe(1, '40.0N 105.3W 1655m'::observer, now()))::numeric, 2) AS el_deg;
```
---
## lunar_lagrange_equatorial
Geocentric RA/Dec of an Earth-Moon Lagrange point. The L1 point lies between Earth and Moon at roughly 84% of the Earth-Moon distance.
### Signature
```sql
lunar_lagrange_equatorial(point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km).
### Example
```sql
-- Earth-Moon L1 distance (~326,000 km from Earth)
SELECT round(eq_distance(lunar_lagrange_equatorial(1, '2000-01-01 12:00:00+00'))::numeric, 0) AS dist_km;
```
---
## galilean_lagrange_observe
Observe a Jupiter-Galilean moon Lagrange point from a ground station. Uses L1.2 theory (Lieske 1998) for the Galilean moon position and VSOP87 for Jupiter's heliocentric position.
### Signature
```sql
galilean_lagrange_observe(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Galilean moon: 0=Io, 1=Europa, 2=Ganymede, 3=Callisto |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation (degrees), range (km), and range rate (km/s).
### Example
```sql
-- Jupiter-Ganymede L3 from Greenwich
SELECT round(topo_elevation(galilean_lagrange_observe(2, 3, '51.4769N 0.0005W 0m'::observer, now()))::numeric, 2) AS el_deg;
```
---
## galilean_lagrange_equatorial
Geocentric RA/Dec of a Jupiter-Galilean moon Lagrange point.
### Signature
```sql
galilean_lagrange_equatorial(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Galilean moon: 0=Io, 1=Europa, 2=Ganymede, 3=Callisto |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km).
### Example
```sql
-- Jupiter-Io L4 sky position
SELECT round(eq_ra(galilean_lagrange_equatorial(0, 4, now()))::numeric, 4) AS ra_hours,
round(eq_dec(galilean_lagrange_equatorial(0, 4, now()))::numeric, 4) AS dec_deg;
```
---
## saturn_moon_lagrange_observe
Observe a Saturn moon Lagrange point from a ground station. Uses TASS17 theory (Vienne & Duriez 1995) for the moon position and VSOP87 for Saturn's heliocentric position.
### Signature
```sql
saturn_moon_lagrange_observe(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Saturn moon: 0=Mimas, 1=Enceladus, 2=Tethys, 3=Dione, 4=Rhea, 5=Titan, 6=Iapetus, 7=Hyperion |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation (degrees), range (km), and range rate (km/s).
### Example
```sql
-- Saturn-Titan L1 from Boulder
SELECT round(topo_azimuth(t)::numeric, 2) AS az,
round(topo_elevation(t)::numeric, 2) AS el
FROM saturn_moon_lagrange_observe(5, 1, '40.0N 105.3W 1655m'::observer, now()) AS t;
```
---
## saturn_moon_lagrange_equatorial
Geocentric RA/Dec of a Saturn moon Lagrange point.
### Signature
```sql
saturn_moon_lagrange_equatorial(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Saturn moon: 0=Mimas, 1=Enceladus, 2=Tethys, 3=Dione, 4=Rhea, 5=Titan, 6=Iapetus, 7=Hyperion |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km).
### Example
```sql
-- Saturn-Titan L1 sky position
SELECT round(eq_ra(saturn_moon_lagrange_equatorial(5, 1, now()))::numeric, 4) AS ra_hours;
```
---
## uranus_moon_lagrange_observe
Observe a Uranus moon Lagrange point from a ground station. Uses GUST86 theory (Laskar & Jacobson 1987) for the moon position and VSOP87 for Uranus's heliocentric position.
### Signature
```sql
uranus_moon_lagrange_observe(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Uranus moon: 0=Miranda, 1=Ariel, 2=Umbriel, 3=Titania, 4=Oberon |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation (degrees), range (km), and range rate (km/s).
### Example
```sql
-- Uranus-Titania L2 from Greenwich
SELECT round(topo_elevation(uranus_moon_lagrange_observe(3, 2, '51.4769N 0.0005W 0m'::observer, now()))::numeric, 2) AS el_deg;
```
---
## uranus_moon_lagrange_equatorial
Geocentric RA/Dec of a Uranus moon Lagrange point.
### Signature
```sql
uranus_moon_lagrange_equatorial(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Uranus moon: 0=Miranda, 1=Ariel, 2=Umbriel, 3=Titania, 4=Oberon |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km).
### Example
```sql
-- Uranus-Oberon L4 sky position
SELECT round(eq_ra(uranus_moon_lagrange_equatorial(4, 4, now()))::numeric, 4) AS ra_hours,
round(eq_dec(uranus_moon_lagrange_equatorial(4, 4, now()))::numeric, 4) AS dec_deg;
```
---
## mars_moon_lagrange_observe
Observe a Mars moon Lagrange point from a ground station. Uses MarsSat theory (Jacobson 2014) for the moon position and VSOP87 for Mars's heliocentric position.
### Signature
```sql
mars_moon_lagrange_observe(body_id int4, point_id int4, obs observer, t timestamptz) → topocentric
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Mars moon: 0=Phobos, 1=Deimos |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `obs` | `observer` | Observer location on Earth |
| `t` | `timestamptz` | Observation time |
### Returns
A `topocentric` with azimuth, elevation (degrees), range (km), and range rate (km/s).
### Example
```sql
-- Mars-Phobos L1 from Boulder
SELECT round(topo_azimuth(t)::numeric, 2) AS az,
round(topo_elevation(t)::numeric, 2) AS el
FROM mars_moon_lagrange_observe(0, 1, '40.0N 105.3W 1655m'::observer, now()) AS t;
```
---
## mars_moon_lagrange_equatorial
Geocentric RA/Dec of a Mars moon Lagrange point.
### Signature
```sql
mars_moon_lagrange_equatorial(body_id int4, point_id int4, t timestamptz) → equatorial
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Mars moon: 0=Phobos, 1=Deimos |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
An `equatorial` with RA (hours), Dec (degrees), and distance (km).
### Example
```sql
-- Mars-Deimos L5 sky position
SELECT round(eq_ra(mars_moon_lagrange_equatorial(1, 5, now()))::numeric, 4) AS ra_hours,
round(eq_dec(mars_moon_lagrange_equatorial(1, 5, now()))::numeric, 4) AS dec_deg;
```
---
## hill_radius
Hill sphere radius (AU) for a Sun-planet system. The Hill sphere is the region where a planet's gravity dominates over the Sun's --- objects beyond this radius are more strongly influenced by the Sun. Computed as r_H = a * (m_p / (3 * m_sun))^(1/3), where a is the instantaneous Sun-planet distance from VSOP87.
### Signature
```sql
hill_radius(body_id int4, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
| `t` | `timestamptz` | Evaluation time |
### Returns
Hill sphere radius in AU.
### Example
```sql
-- Jupiter's Hill sphere (~0.35 AU)
SELECT round(hill_radius(5, '2000-01-01 12:00:00+00')::numeric, 3) AS jupiter_hill_au;
```
```sql
-- All planets
SELECT body_id,
round(hill_radius(body_id, '2000-01-01 12:00:00+00')::numeric, 4) AS hill_au
FROM generate_series(1, 8) AS body_id;
```
---
## hill_radius_lunar
Hill sphere radius (AU) for the Earth-Moon system. Much smaller than planetary Hill spheres since the Moon is far less massive relative to Earth than planets are relative to the Sun.
### Signature
```sql
hill_radius_lunar(t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `t` | `timestamptz` | Evaluation time |
### Returns
Hill sphere radius in AU.
### Example
```sql
SELECT hill_radius_lunar('2000-01-01 12:00:00+00') AS lunar_hill_au;
```
---
## lagrange_zone_radius
Approximate libration zone radius (AU) around a Sun-planet Lagrange point. For L4/L5, this is related to the tadpole/horseshoe orbit domain where Trojan asteroids can remain trapped. For collinear points (L1/L2/L3), it is the linearized stability boundary.
### Signature
```sql
lagrange_zone_radius(body_id int4, point_id int4, t timestamptz) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
| `point_id` | `int4` | Lagrange point: 1-5 (L1-L5) |
| `t` | `timestamptz` | Evaluation time |
### Returns
Zone radius in AU.
### Example
```sql
-- Jupiter L4 libration zone (Trojan swarm extent)
SELECT round(lagrange_zone_radius(5, 4, '2000-01-01 12:00:00+00')::numeric, 4) AS zone_au;
```
---
## lagrange_mass_ratio
CR3BP mass parameter mu = M_planet / (M_sun + M_planet). A diagnostic function useful for verifying the CR3BP solver or understanding the relative gravitational influence of a planet in its system.
### Signature
```sql
lagrange_mass_ratio(body_id int4) → float8
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `body_id` | `int4` | Planet identifier: 1-8 (Mercury-Neptune) |
<Aside type="note">
No timestamp parameter --- mass ratios are compiled-in constants derived from IAU standard gravitational parameters.
</Aside>
### Returns
Dimensionless mass ratio (small positive number; Jupiter is ~0.001, Earth is ~0.000003).
### Example
```sql
SELECT lagrange_mass_ratio(5) AS jupiter_mu,
lagrange_mass_ratio(3) AS earth_mu;
```
---
## lagrange_point_name
Human-readable name for a Lagrange point ID. A simple lookup that converts integer IDs to their standard labels.
### Signature
```sql
lagrange_point_name(point_id int4) → text
```
### Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `point_id` | `int4` | Lagrange point: 1-5 |
### Returns
Text label: `'L1'`, `'L2'`, `'L3'`, `'L4'`, or `'L5'`.
### Example
```sql
SELECT lagrange_point_name(1) AS name;
-- -> 'L1'
```
```sql
-- Use in a query for readable output
SELECT lagrange_point_name(p) AS point,
round(helio_distance(lagrange_heliocentric(3, p, now()))::numeric, 4) AS sun_dist_au
FROM generate_series(1, 5) AS p;
```

View File

@ -149,6 +149,8 @@ lagrange_corotating(double mu, int point_id, double *x, double *y)
return -1;
gamma_new = gamma - f / fp;
if (gamma_new <= 0.0)
gamma_new = gamma * 0.5; /* keep gamma positive */
if (fabs(gamma_new - gamma) < 1e-15)
break;
gamma = gamma_new;
@ -184,6 +186,8 @@ lagrange_corotating(double mu, int point_id, double *x, double *y)
return -1;
gamma_new = gamma - f / fp;
if (gamma_new <= 0.0)
gamma_new = gamma * 0.5; /* keep gamma positive */
if (fabs(gamma_new - gamma) < 1e-15)
break;
gamma = gamma_new;
@ -223,6 +227,8 @@ lagrange_corotating(double mu, int point_id, double *x, double *y)
return -1;
gamma_new = gamma - f / fp;
if (gamma_new <= 0.0)
gamma_new = gamma * 0.5; /* keep gamma positive */
if (fabs(gamma_new - gamma) < 1e-15)
break;
gamma = gamma_new;

View File

@ -1,6 +1,8 @@
-- v020_features: Lagrange point support
-- Tests Sun-planet, Earth-Moon, planetary moon Lagrange points,
-- Hill radius, zone radius, DE fallback, and input validation.
CREATE EXTENSION IF NOT EXISTS pg_orrery;
NOTICE: extension "pg_orrery" already exists, skipping
-- Reference observer: Greenwich, UK
\set obs '''(51.4769,-0.0005,0)'''
-- Reference time: J2000 epoch (2000-01-01 12:00:00 UTC)
@ -284,6 +286,86 @@ SELECT
t
(1 row)
-- ============================================================
-- Tighter L1/L2 precision (4 decimal places)
-- ============================================================
SELECT
round(helio_distance(lagrange_heliocentric(3, 1, :t ::timestamptz))::numeric, 4) AS earth_l1_dist;
earth_l1_dist
---------------
0.9735
(1 row)
SELECT
round(helio_distance(lagrange_heliocentric(3, 2, :t ::timestamptz))::numeric, 4) AS earth_l2_dist;
earth_l2_dist
---------------
0.9932
(1 row)
-- L1 and L2 bracket Earth's heliocentric distance
SELECT
helio_distance(lagrange_heliocentric(3, 1, :t ::timestamptz))
<
helio_distance(planet_heliocentric(3, :t ::timestamptz))
AND
helio_distance(planet_heliocentric(3, :t ::timestamptz))
<
helio_distance(lagrange_heliocentric(3, 2, :t ::timestamptz))
AS l1_earth_l2_ordering;
l1_earth_l2_ordering
----------------------
t
(1 row)
-- ============================================================
-- lagrange_distance_oe — Ceres distance from Jupiter L4
-- Ceres orbits at ~2.77 AU, Jupiter L4 at ~5.2 AU, so distance > 2 AU
-- ============================================================
SELECT
round(lagrange_distance_oe(
5, 4,
oe_from_mpc('00001 3.33 0.12 K24AM 60.07966 73.42937 80.26860 10.58664 0.0789126 0.21406048 2.7660961 0 MPO838504 8738 115 1801-2024 0.65 M-v 30k MPCLINUX 0000 (1) Ceres 20240825'),
:t ::timestamptz
)::numeric, 2) AS ceres_jup_l4_dist;
ceres_jup_l4_dist
-------------------
3.03
(1 row)
-- Distance should be positive and > 2 AU (main belt vs Trojan zone)
SELECT
lagrange_distance_oe(
5, 4,
oe_from_mpc('00001 3.33 0.12 K24AM 60.07966 73.42937 80.26860 10.58664 0.0789126 0.21406048 2.7660961 0 MPO838504 8738 115 1801-2024 0.65 M-v 30k MPCLINUX 0000 (1) Ceres 20240825'),
:t ::timestamptz
) > 2.0 AS ceres_far_from_trojan;
ceres_far_from_trojan
-----------------------
t
(1 row)
-- ============================================================
-- DE fallback for planetary moon Lagrange functions
-- ============================================================
SELECT
round(eq_ra(galilean_lagrange_equatorial_de(0, 4, :t ::timestamptz))::numeric, 4) =
round(eq_ra(galilean_lagrange_equatorial(0, 4, :t ::timestamptz))::numeric, 4)
AS galilean_de_fallback_matches;
galilean_de_fallback_matches
------------------------------
t
(1 row)
SELECT
round(eq_ra(saturn_moon_lagrange_equatorial_de(5, 1, :t ::timestamptz))::numeric, 4) =
round(eq_ra(saturn_moon_lagrange_equatorial(5, 1, :t ::timestamptz))::numeric, 4)
AS saturn_de_fallback_matches;
saturn_de_fallback_matches
----------------------------
t
(1 row)
-- ============================================================
-- Input validation
-- ============================================================

View File

@ -2,6 +2,8 @@
-- Tests Sun-planet, Earth-Moon, planetary moon Lagrange points,
-- Hill radius, zone radius, DE fallback, and input validation.
CREATE EXTENSION IF NOT EXISTS pg_orrery;
-- Reference observer: Greenwich, UK
\set obs '''(51.4769,-0.0005,0)'''
@ -178,6 +180,61 @@ SELECT
round(hill_radius(5, :t ::timestamptz)::numeric, 4)
AS hill_de_matches_vsop;
-- ============================================================
-- Tighter L1/L2 precision (4 decimal places)
-- ============================================================
SELECT
round(helio_distance(lagrange_heliocentric(3, 1, :t ::timestamptz))::numeric, 4) AS earth_l1_dist;
SELECT
round(helio_distance(lagrange_heliocentric(3, 2, :t ::timestamptz))::numeric, 4) AS earth_l2_dist;
-- L1 and L2 bracket Earth's heliocentric distance
SELECT
helio_distance(lagrange_heliocentric(3, 1, :t ::timestamptz))
<
helio_distance(planet_heliocentric(3, :t ::timestamptz))
AND
helio_distance(planet_heliocentric(3, :t ::timestamptz))
<
helio_distance(lagrange_heliocentric(3, 2, :t ::timestamptz))
AS l1_earth_l2_ordering;
-- ============================================================
-- lagrange_distance_oe — Ceres distance from Jupiter L4
-- Ceres orbits at ~2.77 AU, Jupiter L4 at ~5.2 AU, so distance > 2 AU
-- ============================================================
SELECT
round(lagrange_distance_oe(
5, 4,
oe_from_mpc('00001 3.33 0.12 K24AM 60.07966 73.42937 80.26860 10.58664 0.0789126 0.21406048 2.7660961 0 MPO838504 8738 115 1801-2024 0.65 M-v 30k MPCLINUX 0000 (1) Ceres 20240825'),
:t ::timestamptz
)::numeric, 2) AS ceres_jup_l4_dist;
-- Distance should be positive and > 2 AU (main belt vs Trojan zone)
SELECT
lagrange_distance_oe(
5, 4,
oe_from_mpc('00001 3.33 0.12 K24AM 60.07966 73.42937 80.26860 10.58664 0.0789126 0.21406048 2.7660961 0 MPO838504 8738 115 1801-2024 0.65 M-v 30k MPCLINUX 0000 (1) Ceres 20240825'),
:t ::timestamptz
) > 2.0 AS ceres_far_from_trojan;
-- ============================================================
-- DE fallback for planetary moon Lagrange functions
-- ============================================================
SELECT
round(eq_ra(galilean_lagrange_equatorial_de(0, 4, :t ::timestamptz))::numeric, 4) =
round(eq_ra(galilean_lagrange_equatorial(0, 4, :t ::timestamptz))::numeric, 4)
AS galilean_de_fallback_matches;
SELECT
round(eq_ra(saturn_moon_lagrange_equatorial_de(5, 1, :t ::timestamptz))::numeric, 4) =
round(eq_ra(saturn_moon_lagrange_equatorial(5, 1, :t ::timestamptz))::numeric, 4)
AS saturn_de_fallback_matches;
-- ============================================================
-- Input validation
-- ============================================================