Link to home
Start Free TrialLog in
Avatar of tango2009
tango2009

asked on

Rotation matrix

I am trying to learn matrices and how to use them in computer graphics. I have a 3x3 homogenous matrix that I want to use to rotate every point in 2d around point (-1,0) for 90 degrees anti-clockwise (sin(90) =1 and cos(90)=0). How do I go about doing this?

I have the matrices below for the three axis do I need to use all of them?

ASKER CERTIFIED SOLUTION
Avatar of wslb
wslb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
correction ( have the pre-multiplication matrix instead)

the translate matrix T(Tx,Ty) to translate by Tx in the x and Ty in the y direction as


    1      0    Tx
    0      1    Ty
    0      0    1
Avatar of phoffric
phoffric

I think it is confusing that between physics and math circles, there appear to be different preferences about how to represent a vector and how the rotation matrix is affected by it.

You saw the first form below in the earlier link:
    http://en.wikipedia.org/wiki/Rotation_%28mathematics%29

But then you may watch a video on 2d transformations (including homogeneous) in:
     http://www.youtube.com/watch?v=iWxS2zpaRjk&feature=channel
and now it looks a little different (notice the sign of the sin's have changed in the Second Form).

When you program these transformations, it doesn't matter how you represent the vector point and the matrix, as long as you are consistent in your model. Notice that either way you wish to represent the point vector, at least the result is the same for px', py'.
================== First Form =========================================================
    | cos(ß)  -sin(ß)    0 |
R = | sin(ß)   cos(ß)    0 |
    |   0       0        1 |

then we are rotating a vector P into P', where P' = R P
  | cos(ß)  -sin(ß)    0 | |px|   | px cos(ß) - py sin(ß) |   | px' |
= | sin(ß)   cos(ß)    0 | |py| = | px sin(ß) + py cos(ß) | = | py' | 
  |   0       0        1 | |1 |   |           1           |   | h'  |
================ Second Form ===========================================================
    | cos(ß)  sin(ß)   0 |
R = |-sin(ß)  cos(ß)   0 |
    |   0       0      1 |
then we are rotating a vector P into P', where P' = P R (notice the order has changed)
               | cos(ß)  sin(ß)   0 | = [      px'           ,         py'        , h'] 
= [ px, py, 1] |-sin(ß)  cos(ß)   0 | = [ px cos(ß)-py sin(ß), px sin(ß)+py cos(ß), 1 ]
               |   0       0      1 |   
========================================================================================

Open in new window

Again, with translations, there are two common forms based on the vector representation. And again, the results for the translated coordinates are the same using either form. When working with both translation and rotation, it is important to stick to the same form.
============ First Form ===========================
P' = T P
    | 1  0  Tx | | px |   | px+Tx |
P'= | 0  1  Ty | | py | = | py+Ty |
    | 0  0  1  | | 1  |   |   1   |
========== Second Form ============================
P' = P T
                 | 1   0   0 |
P'= [ px, py, 1] | 0   1   0 | = [px+Tx, py+Ty, 1]
                 | Tx  Ty  1 |
===================================================

Open in new window

>> I have the matrices below for the three axis do I need to use all of them?
Using 3x3 homogeneous matrices for translation and rotation in the 2d plane is all that you need.
I hope this clarifies what is being referred to above as pre- and post- multiplication.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this an education question?
>> I have the matrices below for the three axis do I need to use all of them?
Yes. GwynforWeb notes this in http:#34389252
 these actions can be reduced to the single matrix by multiplying these together
  T(-1,0)R(90) T(1,0)
Just tying together what all have noted to form a single matrix using First Form for your problem (ß= +90).
| cos(ß)  -sin(ß)    0 |    | 0  -1    0 |
R  = | sin(ß)   cos(ß)    0 | =  | 1   0    0 |
     |   0       0        1 |    | 0   0    1 |

// For the first translation, Tx = 1, Ty = 0:
     | 1  0  Tx |   | 1  0  1 |  
T1 = | 0  1  Ty | = | 0  1  0 |
     | 0  0  1  |   | 0  0  1 |

// For the last translation, Tx = -1, Ty = 0:
     | 1  0  Tx |   | 1  0 -1 |  
T2 = | 0  1  Ty | = | 0  1  0 |
     | 0  0  1  |   | 0  0  1 |

M = T2 * R * T1

     | 0 -1 -1 |
M =  | 1  0  1 |   // THIS IS THE SINGLE MATRIX THAT YOU NEED
     | 0  0  1 |

// VERIFICATION:

// Your original pivot point, P = (-1,0).
// If you apply M to P, then since it is the pivot point, there should be no change.

      | 0 -1 -1 | |-1|   |-1|
MP =  | 1  0  1 | | 0| = | 0| :: Good, no change, as expected
      | 0  0  1 | | 1|   | 1|

// Now consider the point Q = (0,0).
// Rotating (0,0) 90 degrees around the pivot, P, will bring us to (-1,1).
// Let's verify:

      | 0 -1 -1 | | 0|   |-1|
MP =  | 1  0  1 | | 0| = | 1| :: Good, rotated to (-1,1), as expected
      | 0  0  1 | | 1|   | 1|

Open in new window