vision: keep Matrix3 SVD's U orthonormal for near-zero singular values
- Commit
69a83feec88d10eb96fdd43eb5e26c16cb102808- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 19:16 UTC (28 days ago)
- Parents
c844d55
u_i = M v_i / sigma_i is meaningless when sigma_i is near zero: the Jacobi eigenvector then sits numerically in M's null space and the quotient comes out near zero instead of unit. An essential matrix (sigma = 1, 1, 1.3e-9) produced a U whose third column had norm 3e-9, so epipolar pose recovery read its translation direction from noise. The 1e-12 absolute threshold could not see it. svd() now orthogonalises each candidate column against the accepted ones and marks it degenerate — for the existing cross-product / Gram-Schmidt completion in fixup_orthonormal — when it does not survive as a unit vector. Verified: cargo +1.97.0 test --locked in library/vision (7 passed) and measure (44 + 9 passed, including the epipolar integration tests that exposed this).
Diff
library/vision/src/main/rust/src/linalg/matrix3.rs
diff --git a/library/vision/src/main/rust/src/linalg/matrix3.rs b/library/vision/src/main/rust/src/linalg/matrix3.rsindex 55bf0b9115..3544c61e9f 100644--- a/library/vision/src/main/rust/src/linalg/matrix3.rs+++ b/library/vision/src/main/rust/src/linalg/matrix3.rs@@ -182,8 +182,27 @@ impl Matrix3<f64> { for i in 0..3 { let vi = vmat.column(i); let mvi = *self * vi;- if sigma[i] > 1e-12 {- u.set_column(i, mvi / sigma[i]);+ if sigma[i] <= 1e-12 {+ degenerate[i] = true;+ continue;+ }+ // u_i = M v_i / σ_i is only as good as v_i, and for a near-zero+ // σ_i the Jacobi eigenvector is numerically in M's null space:+ // the quotient comes out near zero instead of unit (an essential+ // matrix's σ = (1, 1, 1e-9) did exactly this, and every consumer+ // indexing u.column(2) — the translation direction — read noise).+ // Orthogonalise against the accepted columns and let the fixup+ // below complete any column that does not survive as unit.+ let mut cand = mvi / sigma[i];+ for (j, _) in degenerate.iter().enumerate().take(i) {+ if !degenerate[j] {+ let uj = u.column(j);+ cand = cand - uj * uj.dot(&cand);+ }+ }+ let n = cand.norm();+ if n > 0.5 {+ u.set_column(i, cand / n); } else { degenerate[i] = true; }