Reputation: 1352
I have been working on 3D rotations using a 4x4 matrix. I have come across a lot of great information, but I'm lacking understanding in one topic. I have yet to understand how to determine the angle for axis.
If we look here we'll find a wiki page describing Rotation matrix from axis and angle. I know that the axis is the cross product of the two vectors. For example:
Vector1: (1,0,0)
Vector2: (0,0,1)
axis = Cross(Vector1, Vector2)
However, I do not know how to get the angle. If anyone has any pro tips on calculating the angle I would be grateful.
Upvotes: 0
Views: 946
Reputation: 15035
There is a well-known identity linking the cross-product of two vectors to the angle between them:
Where theta
is the smaller angle. However, this can be in the range [0, 180]
, over which the inverse sine function is multi-valued: an acute angle theta
is such that sin(theta) = sin(180 - theta)
, so we can't directly obtain it from this formula.
We can use the dot-product instead:
The inverse cosine function is single-valued over this range, so we can use it!
dot = Dot(Vector1, Vector2)
cos = dot / (Len(Vector1) * Len(Vector2))
theta_radians = acos(cos)
theta_degrees = theta_radians * 180 / PI
Upvotes: 2