Calculating 3d rotation around random axis
Posted
by
mitim
on Programmers
See other posts from Programmers
or by mitim
Published on 2012-11-27T09:58:13Z
Indexed on
2012/11/27
11:20 UTC
Read the original article
Hit count: 294
This is actually a solved problem, but I want to understand why my original method didn't work (hoping someone with more knowledge can explain).
(Keep in mind, I've not very experienced in 3d programming, having only played with the very basic for a little bit...nor do I have a lot of mathematical experience in this area).
I wanted to animate a point rotating around another point at a random axis, say a 45 degrees along the y axis (think of an electron around a nucleus). I know how to rotate using the transform matrix along the X, Y and Z axis, but not an arbitrary (45 degree) axis.
Eventually after some research I found a suggestion: Rotate the point by -45 degrees around the Z so that it is aligned. Then rotate by some increment along the Y axis, then rotate it back +45 degrees for every frame tick. While this certainly worked, I felt that it seemed to be more work then needed (too many method calls, math, etc) and would probably be pretty slow at runtime with many points to deal with.
I thought maybe it was possible to combine all the rotation matrixes involve into 1 rotation matrix and use that as a single operation.
Something like:
[ cos(-45) -sin(-45) 0]
[ sin(-45) cos(-45) 0] rotate by -45 along Z
[ 0 0 1]
multiply by
[ cos(2) 0 -sin(2)]
[ 0 1 0 ] rotate by 2 degrees (my increment) along Y
[ sin(2) 0 cos(2)]
then multiply that result by (in that order)
[ cos(45) -sin(45) 0]
[ sin(45) cos(45) 0] rotate by 45 along Z
[ 0 0 1]
I get 1 mess of a matrix of numbers (since I was working with unknowns and 2 angles), but I felt like it should work. It did not and I found a solution on wiki using a different matirx, but that is something else.
I'm not sure if maybe I made an error in multiplying, but my question is: this is actually a viable way to solve the problem, to take all the separate transformations, combine them via multiplying, then use that or not?
© Programmers or respective owner