MATLAB: How to get a 3D rotation matrix

mathematics

How can I get a 3D rotation matrix by only knowing a degree? That means, firstly, set a degree, say, 10, then generate a 3D rotation matrix randomly in order that for any unit vector v from the origin, the angle between v and the rotated vector Rv would be 10 degree. Thank you so much!!

Best Answer

If you look at the command makehgtform , you'll find a form that looks like this:
M = makehgtform('axisrotate',[ax ay az],t)
The axis [ax ay az] needs to be normal to the vector you want to rotate. As others have noted in the comments, this matrix will apply the same rotation to all of the vectors which lie in the plane which is normal to [ax ay az], but it will rotate vectors which do not lie in that plane by a smaller amount.
The angle t is in radians, so you'll need to convert.
Also, this command returns a 4x4 matrix because it supports translations. You just want the upper 3x3.