0

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.

Travis Pettry
  • 1,220
  • 1
  • 14
  • 35
  • this [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) might interest you. – Spektre Aug 29 '17 at 19:11

1 Answers1

2

There is a well-known identity linking the cross-product of two vectors to the angle between them:

enter image description here

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:

enter image description here

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
meowgoesthedog
  • 14,670
  • 4
  • 27
  • 40
  • Thank you for your help. I have another post you might be able to help with. If you get the time you can check it out here https://stackoverflow.com/questions/45986652/matrix-rotation-around-an-arbitrary-axis-bug – Travis Pettry Aug 31 '17 at 16:58