-
Matrix Rotation
Hi, I am looking for a code that will perform a matrix rotation around a desired point and NOT about an axis for example. I am looking for references in this area that would help me achieve this rotation. I know it is possible, but cannot find anything relevant in the literature.
Thanks
-
I may be wrong, but all rotation happens about a central point. If you want to rotate based on a different point, you must fist modify the matrix to match this point - i.e. subtract the distance to the base-point from the central point. There was a discussion about this subject not so long ago.
--
Mats
-
Do you mean rotation in 2D? As mats says, you need to translate the point to the origin, do the translation using the usual [[cos -sin] [sin cos]] matrix, and translate back. (In 3D there is no such thing as rotation about a point.)
-
Look up "homogeneous coordinates" for an elegant way to include translation in your matrix multiplications.
--
Computer Programming: An Introduction for the Scientifically Inclined
-
What do you mean by matrix translation? A matrix which rotates a vector? Then tabstop gave the answer. in 3D the rotation is (+1 for a rotation, -1 for a mirror-rotation)
Code:
+/-1 0 0
0 cos(phi) sin(phi)
0 -sin(phi) cos(phi)
edit: sorry for the horrible indentation...
-
I have some inherited code, but it has no references in it. However the basic operation is to define a rotation centre (the point to be rotated defined as a vector). Then a rotation occurs by phi and then by theta. One can see how the rotation works for phi as this works similarly as above, however cannot get any references or derivations for the rotation about theta. I have listed what is going in the program below.
There are two components:
One is a rotation about phi, which is with respect to an axis and this simply takes the form:
| cos (phi) -sin (phi) 0 |
| sin (phi) cos (phi) 0 |
| 0 0 1 |
That I agree is rotation about a z axis.
Then there is the theta part which is much more complex. This I have broken down into some of the constituent parts. I cannot find anywhere on the wen where this might have come from. The summation of A, B and C leads to a rotation about theta, assuming some arbitrary axis, which one can assume is that same as before.
Code:
A
==
| sin^2(theta)*(1-cos(theta)) (1-cos(theta))cos(theta)sin(theta) 0 |
| -sin(theta)cos(theta)*(1-cos(theta)) cos^2(1-cos(theta)) 0 |
| 0 0 0 |
B
==
| 0 0 -cos(theta)*sin(theta) |
| 0 0 sin^2(theta) |
| cos(theta)sin(theta) sin^2(theta) 0 |
C
==
| cos(theta) 0 0 |
| 0 cos(theta) 0 |
| 0 0 cos(theta) |