Thread: Matrix Rotation

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    41

    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

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.)

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    53
    Look up "homogeneous coordinates" for an elegant way to include translation in your matrix multiplications.

    --
    Computer Programming: An Introduction for the Scientifically Inclined

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    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...

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    41
    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) |

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  3. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM