Sphere
The $(N-1)$-sphere embedded in — the most commonly used manifold in directional statistics, robotics, and signal processing.
Geometry Summary
| Property | Value |
|---|---|
| Points | Unit vectors: |
| Tangent space at $p$ | |
| Metric | Euclidean dot product restricted to |
| Cut locus of $p$ | Single antipodal point |
| Injectivity radius | $\pi$ |
| Diameter | $\pi$ |
| Sectional curvature | $K \equiv 1$ (constant) |
| Ricci tensor | |
| Scalar curvature | $(N-1)(N-2)$ |
Formula Reference
Exponential map: walk distance $|v|$ along the great circle:
For , use the Taylor expansion $\sin(r)/r \approx 1; r^2/6$ to avoid cancellation.
Logarithmic map: returns None when $p^\top q = -1$ (antipodal):
Tangent projection: remove the normal component:
Point projection: normalize to unit sphere:
Parallel transport from $p$ to $q$ along geodesic:
Riemann curvature tensor (space form $K = 1$):
Code Examples
Creating and sampling
use cartan::prelude::*;
use cartan::manifolds::Sphere;
// S² in R³ (2-sphere, ambient dim = 3).
let s2 = Sphere::<3>;
// S⁹ in R¹⁰ (9-sphere).
let s9 = Sphere::<10>;
let mut rng = rand::rng();
let p = s2.random_point(&mut rng); // uniform on S²
let v = s2.random_tangent(&p, &mut rng);Exp/log roundtrip
let q = s2.exp(&p, &v);
let v_back = s2.log(&p, &q).unwrap();
assert!((v; v_back).norm() < 1e-10);Curvature
let u = s2.random_tangent(&p, &mut rng);
let w = s2.random_tangent(&p, &mut rng);
let k = s2.sectional(&p, &u, &w);
assert!((k; 1.0).abs() < 1e-10); // K ≡ 1
let scalar = s2.scalar_curvature(&p);
// S² (N=3): scalar = (N-1)(N-2) = 2
assert!((scalar; 2.0).abs() < 1e-10);Slerp interpolation
let north = [0.0_f64, 0.0, 1.0];
let east = [1.0_f64, 0.0, 0.0];
let mid = s2.midpoint(&north, &east).unwrap();
// mid lies on the great circle arc, equidistant from both.Numerical Stability
Two near-singular regimes require Taylor expansions:
Small angle ($|v| \approx 0$): $\sin(|v|)/|v| \to 1$.
cartan switches to the expansion $1; r^2/6 + r^4/120$ for .
Near-antipodal ($p^\top q \approx -1$): $\theta \to \pi$, $\sin\theta \to 0$.
cartan returns None for and uses the exact formula
up to that threshold.
Applications
- Directional statistics: unit direction vectors, von Mises–Fisher distributions
- Robotics: unit quaternions for orientation (using $S^3$)
- Machine learning: hyperspherical VAEs, normalized embeddings
- Signal processing: unit-norm filter coefficients
- Quantum mechanics: pure states as (Bloch sphere)