1
votes

While playing with quaternions, I noticed that I could not find the angle of rotation of a vector using the dot product between this vector, and its original position. In my example, I rotated a vector by 90 degrees around an arbitrary axis, but the dot product yielded a different angle.

    // Axis of rotation (unit vector).
    Vec3 Axis = Vec3(1, 1, 0) / sqrt(1 + 1 + 0);
    
    // Creates a quaternion that will rotate a point by 90 degrees around the (1, 1, 0) axis.
    Quat q(cos(3.14 / 4), Axis * sin(3.14 / 4));
    
    // Creates a point.
    Vec3 Point = Vec3(1, 0, 0);
    
    // Rotates the point by q.
    Quat Rot = q * Quat(0, Point) * q.GetConjugate();// Rot == (0, 0.5, 0.5, -0.707)
    
    // Getting Rot's coordinates.
    Vec3 v = Vec3(Rot.x, Rot.y, Rot.z);
    
    // Angle is equal to 1.047, but it should be 1.57 (3.14/2)...
    float Angle = acos(Dot(Point, v));
    

Note that every vector and quaternion is of length of 1.

I find that really intriguing, because the shortest angle between a vector rotated by 90 degrees and its original position is 90 degrees.

So my question is: why am I not getting 1.57 radians? What I am not understanding here?

Thank you for your attention.

1

1 Answers

1
votes

With the dot product, you are measuring the angle between the initial vector, and the rotated vector, which is generally not the same as the magnitude of the applied rotation.

Imagine if your point was on the rotation axis, then the point would not move when the rotation is applied. To test this, set your point to (1, 1, 0)/sqrt(2), and the angle should be zero.

Then set the point to (1,-1,0)/sqrt(2) and you should get your expected pi/2.

Since you are rotation about the origin, only the component of the point perpendicular to the axis of rotation is effected by the rotation.

A good reference: https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula