1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
//! Projection onto the Kustaanheimo–Stiefel constraint surface — the B2 "evolve freely, then project
//! onto the constraint manifold" step of the perturbed-conformal trajectory split (Gap-3 Resolution 1),
//! the Leray/Hodge analogue for the trajectory axis.
//!
//! A KS phase state `(u, w)` (`u` the regularised position 4-vector, `w = u'` its fictitious-time
//! velocity) corresponds to a physical 3-D `(r, v)` **iff** the **bilinear relation** holds:
//! `b(u, w) = u₄w₁ − u₃w₂ + u₂w₃ − u₁w₄ = 0` (the 4th component of `L(u)·w`; it is the KS realisation of
//! the Sp(2,R) gauge condition — the heavier Bars `(4,2)` packaging is optional, FS-1). A measurement
//! update on `w` can leave the surface; this module measures the residual and projects `w` back to the
//! nearest constraint-satisfying velocity under the **fixed gauge that holds `u`** (the position 4-vector
//! is unchanged; only the constraint-violating component of the velocity is removed).
//!
//! # References
//! * Stiefel, E. L. & Scheifele, G., *Linear and Regular Celestial Mechanics*, Springer (1971), §19.
use cratePhysicsError;
use RealField;
/// The KS bilinear constraint residual `b(u, w) = u₄w₁ − u₃w₂ + u₂w₃ − u₁w₄`. Zero iff `(u, w)` maps to
/// a physical 3-D `(r, v)`.
/// Project the KS velocity `w` onto the constraint surface `b(u, ·) = 0`, returning the **nearest**
/// constraint-satisfying velocity under the fixed gauge that keeps `u`. The constraint is linear in `w`
/// with gradient `g = (u₄, −u₃, u₂, −u₁)` and `|g|² = |u|²`, so the orthogonal projection removes the
/// violating component: `w' = w − (b(u,w)/|u|²)·g`. Idempotent.
///
/// # Errors
/// [`PhysicsError::Singularity`] if `|u|² = 0` (no position to gauge against).