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)
.
If norm(a) > 0
and norm(b) > 0
, then q
can be calculated with good
accuracy no matter what the positional relationship between a
and b
is.
However, this function does not guarantee what the axis of rotation will be.
If you want the rotation axis to be orthogonal to vectors a
and b
, you can use rotate_a_to_b_shotest
.
If you enter a zero vector either a
or b
, it returns None
.
ยง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 );