nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Rotation3 angle from 2 vectors

Open Alphapage opened this issue 2 years ago • 1 comments

Hello,

I use this snippet to rotate my vector:

        use nalgebra::{Point3, Rotation3, Vector3};
        use std::f32;
        let axisangle = Vector3::y() * f32::consts::FRAC_PI_2;
        // Point and vector being transformed in the tests.
        let pt = Point3::new(4.0, 5.0, 6.0);
        let vec = Vector3::new(4.0, 5.0, 6.0);
        let rot = Rotation3::new(axisangle);

        // assert_relative_eq!(
        //     rot * pt,
        //     Point3::new(6.0, 5.0, -4.0),
        //     epsilon = 1.0e-6
        // );
        // assert_relative_eq!(
        //     rot * vec,
        //     Vector3::new(6.0, 5.0, -4.0),
        //     epsilon = 1.0e-6
        // );

The problem is that I want to get f32::consts::FRAC_PI_2 rotation angle back from result (ie Vector3::new(6.0, 5.0, -4.0)) and origin (ie Vector3::new(4.0, 5.0, 6.0)). I can't find any function like Rotation3::get_angle(axis_angle,V1,V2). Does this function exists or is it planned for implementation ? Thank you in advance for your answer.

Alphapage avatar Sep 18 '23 17:09 Alphapage

You cannot determine the angle a given rotation matrix $R$ rotates by just by knowing a given vector $\vec{a}$ and where it goes after being rotated ($R\vec{a}$). For example, if the vector $\vec{a}$ is aligned with the axis of rotation, it will not move regardless of rotation angle. To uniquely determine the axis and angle of a rotation from pairs of vectors and their images, you need at least 2 pairs.

vasilNnikolov avatar Jan 04 '24 18:01 vasilNnikolov