Thread: 2d Transformations : Is the following correct ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Why do you have a 3x3 transformation matrix when you only have a 2-d graph? The result of your transformation should be another 1x2 matrix, representing the new x and y, x' and y'. Also, you are performing 3 transformations. You are scaling, sliding and rotating, so I would use 3 separate 2x2 matrices, one for each transformation. You can combine them later, once you get it. As for the 3 matrices, here is how they work:

    1. Scaling: Your old x-axis length was pi/2. The new length needs pythagoreans theorem: sqrt((c-x1)^2 + (d-y1)^2). The scaling factor is new/old. You do similar for the y scaling factor.
    2. Rotation: You must figure out how much you rotated by. Make a right triangle with (x1,y1), (c,y1) and (c,d). Use the lengths of the sides to figure out theta, your angle of rotation.
    3. Translation: You moved to the right x1 units and up y1 units. You will add this number after you scale and rotate.


    Your scaling matrix is just a diagonal. You multiply the x coordinate by the x scaling factor, and the y coordinate by the y scaling factor:
    Code:
    [x'] = [Sx  0] [x]
    [y']   [0  Sy] [y]
    Your rotation matrix looks like:
    Code:
    [x'] = [cos t  -sin t] [x]     where t is theta, your angle of rotation
    [y']   [sin t   cos t] [y]
    And your translation matrix is a 1x2 matrix that you add instead of multiply:
    Code:
    [x'] = [x1] + [x]
    [y']   [y1]   [y]
    Putting it all together, you get:
    Code:
    [x'] = [cos t  -sin t] [Sx  0] [x] + [x1]
    [y']   [sin t   cos t] [0  Sy] [y]   [y1]
    At least, I'm pretty sure that's how you'd do it. Try taking some points with known cooridanates both before and after, and plug them to see if they transform correctly. Some "easy" known points are (0,0)-->(x1,y1), (0,1)-->(a,b) and (pi/2,0)-->(c,d).
    Last edited by anduril462; 05-15-2012 at 10:09 AM. Reason: Fixed rotation matrices

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by anduril462 View Post
    Why do you have a 3x3 transformation matrix when you only have a 2-d graph?
    Err... it is called Homogeneous coordinates. I thought it simplified things here.
    And the (2x2) matrix in the upper left corner is my attempt in combining and simplifying rotation and scaling.
    Last edited by manasij7479; 05-15-2012 at 09:46 AM.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by manasij7479 View Post
    Err... it is called Homogeneous coordinates. I thought it simplified things here.
    And the (2x2) matrix in the upper left corner is my attempt in combining and simplifying rotation and scaling.
    Ahh, clearly you already know more than I do about the subject (screw you work, I'm learning geometry today!)...have you plugged in your know points? Does they transform properly?

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by anduril462 View Post
    have you plugged in your know points? Does they transform properly?
    The origin does and so does (pi/2,0) but they are simple.
    I'm trying to work out if the sine's maxima does.. but the geometry is tripping me up a little.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Hmm...I'm pretty sure your setup doesn't work. Your vector should be [x y 1], so you multiply 1 by the translation amounts and add it to your final result. You also need to put [x1 y1 1] across the bottom, not down the right side. It would work on the right side only if you made your horizontal vector vertical and moved it to the right side of your transformation matrix for the multiplication. I'll have to do more reading before I can tell you whether the scale and rotate portion is correct.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by manasij7479 View Post
    And the (2x2) matrix in the upper left corner is my attempt in combining and simplifying rotation and scaling.
    Can you tell me how you arrived at that simplification, it would probably be easier for me to tell you if you're right that way, then trying to figure out what you did from just that 2x2.

  7. #7
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by anduril462 View Post
    Can you tell me how you arrived at that simplification, it would probably be easier for me to tell you if you're right that way, then trying to figure out what you did from just that 2x2.
    The fact that the components of the unit vectors (i,j,k) in the new frame as represented from the old frame are the rows of the transformation matrix, in order.
    (no k here, though)

    EDIT:
    It is actually the opposite.
    It is the components of the old i and j when transformed into the new frame.
    Last edited by manasij7479; 05-15-2012 at 10:26 AM.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Ooh, I think I get it now. The 2x2 for your first matrix appears to be correct, but your vector and translation is wrong for the reasons I mentioned in post #6. Your vector needs a 1, not a 0, and you need to move the translation values to the bottom row. That makes your 3 axis points map correctly. That should be sufficient, but if you want to double check, pick some easier points, like the midpoints of the axis and the midpoint between (0,1) and (pi/2,0) should map to the midpoint between (a,b) and (c,d).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Transformations
    By Homunculus in forum Game Programming
    Replies: 4
    Last Post: 11-01-2011, 05:21 PM
  2. Numerical System Transformations - Lecture
    By vurdlak in forum C++ Programming
    Replies: 2
    Last Post: 03-16-2006, 08:16 AM
  3. opengl model transformations
    By curlious in forum Game Programming
    Replies: 3
    Last Post: 09-06-2004, 02:30 PM
  4. DirectX transformations
    By confuted in forum Game Programming
    Replies: 9
    Last Post: 08-02-2003, 07:41 PM