pub fn rotate_a_to_b<T>(a: Vector3<T>, b: Vector3<T>) -> Option<Quaternion<T>>where
T: Float,Expand description
Calculate the Versor to rotate from vector a to vector b (Without singularity!).
This function calculates q satisfying b = point_rotation(q, a) when norm(a) = norm(b).
§Characteristics
- Robustness: This function can accurately calculate the versor regardless of the
combination of vector orientations (however,
norm(a) > 0andnorm(b) > 0). - Axis Ambiguity: This function provides no guarantees regarding the direction
or regularity of the rotation axis. If you require a rotation axis that is orthogonal
to both vector
aand vectorb, you should userotate_a_to_b_shortestfunction.
§Returns
Returns None if either input vector a or b is a zero vector,
as a rotation cannot be uniquely defined in that case.
§Examples
let a: Vector3<f64> = [1.5, -0.5, 0.2];
let b: Vector3<f64> = [0.1, 0.6, 1.0];
let q = rotate_a_to_b(a, b).unwrap();
let b_check = point_rotation(q, a);
let b_u = normalize(b);
let b_check_u = normalize(b_check);
assert!( (b_u[0] - b_check_u[0]).abs() < 1e-12 );
assert!( (b_u[1] - b_check_u[1]).abs() < 1e-12 );
assert!( (b_u[2] - b_check_u[2]).abs() < 1e-12 );