Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matrix Multiplication to translate object with given vertices

  1. Apr 17, 2012 #1
    This was a question for a test of mine. Im unsure how to translate the object from the left image(Fig.1) to the right (Fig.2). I am to use matrix multiplication..

    Do i start with the vertices in Fig.1 as a matrix, as in |0 -1 -2 0 -2 -1 |
    .............................................................................|0 0 0 2 2 3 |

    (I apologize, i dont know how to make large square brackets..)
     

    Attached Files:

  2. jcsd
  3. Apr 17, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey Phys121VIU.

    In terms of translation matrices used in computer graphics, it's easier to use a 4x4 matrix with a 'w' co-ordinate to perform the transformation and then basically project a 4-vector to a 3-vector.

    In other words your matrix will look like this:

    [a b c d]
    [e f g h]
    [i j k l]
    [m n o p]

    where [d h l p]^T is going to be the translation co-effecients corresponding to the vector <x,y,z,w> for translation. If you make the upper LHS 3x3 matrix an identity and your [d h l p] matrix corresond to <Tx,Ty,Tz,0> then when you apply this matrix to a point X you will get Mx = x + T where T is the translation vector above.

    Although the output vector is four-dimensional, your w component will be 0 and will reduce to a normal 3d vector if you project it onto the 3-D space where w = 0.

    In terms of having a general matrix to do this for all the points, you can not have a 3D matrix that can be applied to all points to give you that result if you want the matrix itself to be a constant as opposed to something that varies with points.

    If you want to do it with 3D matrices, then you will have to create a matrix that is a function of the points themselves and this will require extra work.

    My guess is that they probably don't want something complicated, so a 4x4 matrix will do the trick along with a projection to the constraint w = 0.
     
  4. Apr 17, 2012 #3

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    [tex]\begin{bmatrix}0 & -1 & -2 & 0 & -2 & -1 \\ 0 & 0 & 0 & 2 & 2 & 3\end{bmatrix}[/tex]
    (Click on that to see the code.)

    Those are the coordinates of 6 points in two-dimensions. A 2 by 2 matrix, of the form
    [tex]\begin{bmatrix}cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta)\end{bmatrix}[/tex]
    gives a rotation around the origin through angle [itex]\theta[/itex]. A translation would, normally, be a vector to be added.

    But you can, as chiro says, use "projective" coordinates, with point (x, y) represented by (x, y, 1) with the understanding that if some operation causes the third coordinate to change, we divide each coordinate by that to get back to 1- the point (ax, ay, a) is the same point as (x, y, 1). However, I think chiro is giving the case of projective coordinates in 3 dimensions so the matrix has 3+ 1= 4 rows and columns. If you are working in two dimensions so your matrix should have 2+ 1= 3 rows and columns.

    Doing that, a translation, adding a to the x-coordinate and b to the y coordinate, is given by
    [tex]\begin{bmatrix}1 & 0 & a \\ 0 & 1 & b \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}x \\ y \\ 1\end{bmatrix}= \begin{bmatrix}x+ a\\ y+ b\\ 1\end{bmatrix}[/tex]
     
    Last edited: Apr 17, 2012
  5. Apr 17, 2012 #4
    Thanks for this!


    Ok i am begining to understand this question..To translate, say the top point of the object,
    \begin{bmatrix}-1 \\ 3\end{bmatrix} to the new coordinate \begin{bmatrix}2 \\ 5\end{bmatrix} i would use
    \begin{bmatrix}1 & 0 & 3 \\ 0 & 1 & 2 \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}-1 \\ 3 \\ 1\end{bmatrix}= \begin{bmatrix}(-1)+3\\ 3+2\\ 1\end{bmatrix}

    That is awesome!! Thanks so much

    Is there a quicker way to translate all of the coordinates? like in the 2x6 matrix shown above?

    It seems if I go about the same method, I would need a 6x6 matrix..?
     
  6. Apr 17, 2012 #5

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    No, you can use the same "translation" matrix, just do it as a single matrix multiplication using all of the points as a single matrix:
    [tex]\begin{bmatrix}1 & 0 & 3 \\ 0 & 1 & 2 \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}0 & -1 & -2 & 0 & -2 & -1 \\ 0 & 0 & 0 & 2 & 2 & 3 \\ 1 & 1 & 1 & 1 & 1 & 1\end{bmatrix}=\begin{bmatrix}3 & 2 & 1 & 3 & 1 & 2 \\ 2 & 2 & 2 & 4 & 4 & 5 \\ 1 & 1 & 1 & 1 & 1 & 1 \end{bmatrix}[/tex]
     
    Last edited: Apr 17, 2012
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matrix Multiplication to translate object with given vertices
  1. Multiplication of matrix (Replies: 10)

  2. Matrix multiplication (Replies: 1)

  3. Matrix multiplication? (Replies: 5)

  4. Matrix multiplication (Replies: 1)

  5. Matrix multiplication (Replies: 14)

Loading...