SatelliteToolboxLegendre.jl
Associated Legendre functions and derivatives with multiple normalization options. Repo: JuliaSpace/SatelliteToolboxLegendre.jl
Computing Legendre Functions
# P[n+1, m+1] = P_{n,m}[cos(ϕ)]
P = legendre(Val(:full), ϕ, n_max) # Full normalization
P = legendre(Val(:schmidt), ϕ, n_max, m_max) # Schmidt semi-normalization
P = legendre(Val(:unnormalized), ϕ, n_max) # Unnormalized
# In-place (zero-allocation)
legendre!(Val(:full), P, ϕ, n_max, m_max)
Computing Derivatives
(dP, P) = dlegendre(Val(:full), ϕ, n_max) # Returns both dP and P
dlegendre!(dP, ϕ, P, n_max, m_max) # In-place (P must be pre-computed)
Key Conventions
- First argument
N selects normalization: Val(:full), Val(:schmidt), Val(:unnormalized)
- Angle
ϕ in radians
- Indexing:
P[n+1, m+1] for degree n, order m
- Optional
ph_term=true includes Condon-Shortley phase (-1)^m
- In-place variants infer
n_max/m_max from matrix dimensions if omitted
- Zero external dependencies (pure Julia)
1---2name: satellitetoolbox-legendre3description: SatelliteToolboxLegendre.jl for computing associated Legendre functions and derivatives. Use when working with spherical harmonics, gravity field expansions, or geomagnetic field computations.4---5
6# SatelliteToolboxLegendre.jl
7
8Associated Legendre functions and derivatives with multiple normalization options. Repo: [JuliaSpace/SatelliteToolboxLegendre.jl](https://github.com/JuliaSpace/SatelliteToolboxLegendre.jl)
9
10## Computing Legendre Functions
11
12```julia
13# P[n+1, m+1] = P_{n,m}[cos(ϕ)]
14P = legendre(Val(:full), ϕ, n_max) # Full normalization
15P = legendre(Val(:schmidt), ϕ, n_max, m_max) # Schmidt semi-normalization
16P = legendre(Val(:unnormalized), ϕ, n_max) # Unnormalized
17
18# In-place (zero-allocation)
19legendre!(Val(:full), P, ϕ, n_max, m_max)
20```
21
22## Computing Derivatives
23
24```julia
25(dP, P) = dlegendre(Val(:full), ϕ, n_max) # Returns both dP and P
26dlegendre!(dP, ϕ, P, n_max, m_max) # In-place (P must be pre-computed)
27```
28
29## Key Conventions
30- First argument `N` selects normalization: `Val(:full)`, `Val(:schmidt)`, `Val(:unnormalized)`
31- Angle `ϕ` in **radians**
32- Indexing: `P[n+1, m+1]` for degree `n`, order `m`
33- Optional `ph_term=true` includes Condon-Shortley phase `(-1)^m`
34- In-place variants infer `n_max`/`m_max` from matrix dimensions if omitted
35- Zero external dependencies (pure Julia)