Skip to main content

absolute_orientation

Function absolute_orientation 

Source
pub fn absolute_orientation(
    pairs: &[(Point, Point)],
    weights: Option<&[f64]>,
) -> OgeomResult<Transform>
Expand description

The rigid transform carrying the first point of each pair onto the second with the least weighted sum of squared distances, in closed form.

The rotation is the unit quaternion of the largest eigenvalue of the symmetric 4×4 matrix of the pairs’ weighted cross-covariance about their weighted centroids, and the translation then carries the first centroid onto the second. A quaternion is a rotation by construction, so a set a mirror would fit better (coplanar points, or noisy ones) still gets the best proper rotation, never a reflection. Pairs that hold no rotation (all one point) get none; pairs on one line get one about it that carries them exactly. Equal weights where weights is None.

The cross-covariance holds the turn about a set’s long axis in its spread off that axis squared, so pairs spread by δ off a line of length L are carried to within about ε · L² / δ: within 1e-12 · L for δ above some 2e-4 · L, and exactly on the line itself.

§Errors

OgeomError::Domain for no pairs, a point or weight not finite, a negative weight, or weights summing to zero; OgeomError::Dimension for weights not one per pair.