Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Need some clarification on transformation matrices

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2012
    Posts
    101

    Need some clarification on transformation matrices

    Hello, I need some clarification on transformation matrices. I have given x ( x1, x2, x3), y (y1, y2, y3) and z (z1, z2, z3) axis basis vectors. Does the required rotation transformation matrix look like this:

    |x1 y1 z1 0|
    |x2 y2 z2 0|
    |x3 y3 z3 0|
    |0 0 0 1 |


    If I multiply an object by this transformation matrix, I don't get the required transformation.
    Please give some clarification.

    Thanks.

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    Not even close!
    And where is the rotation angle?

    Take a look at Appendix F of the Red Book, or any other 3D graphics book covering the transformations.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,167
    Quote Originally Posted by Lee_Jennifer_82 View Post
    Hello, I need some clarification on transformation matrices. I have given x ( x1, x2, x3), y (y1, y2, y3) and z (z1, z2, z3) axis basis vectors. Does the required rotation transformation matrix look like this:

    |x1 y1 z1 0|
    |x2 y2 z2 0|
    |x3 y3 z3 0|
    |0 0 0 1 |
    Yes. This is the UVW-to-XYZ basis transform (where X, Y, and Z are the UVW vectors expressed in the XYZ basis).

    Of course if you want the XYZ-to-UVW transform instead, you want the inverse (if your basis is orthonormal, just take the transpose).

    (NOTE: I'm using OpenGL column major order in my response above. If you're using row-major, transpose the above.)
    Last edited by Dark Photon; 06-30-2014 at 06:14 PM.

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    388
    Quote Originally Posted by Dark Photon View Post
    Yes. This is the UVW-to-XYZ basis transform (where X, Y, and Z are the UVW vectors expressed in the XYZ basis).
    Of course if you want the XYZ-to-UVW transform instead, you want the inverse (if your basis is orthonormal, just take the transpose).
    What he said.

  5. #5
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    I' sorry for not understanding the question on the first glance and giving a wrong advice. OP called it a rotation matrix, which confused me. It was a model-view matrix defined by the orientation of the local coordinate system.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Dec 2012
    Posts
    101
    Thank you all for the reply. Have any one have done matrix transformation from OpenCV to OpenGL? I am doing by multiplying the opencv matrix by the following:

    |1 0 0 0|
    |0 1 0 0|
    |0 0 1 0|
    |0 0 0 1|

    It makes the y, z axis basis vectors reverse.

    Could any one post some reply regarding this? Recently I did some search in the web about transforming opencv matrix to opengl matrix, but didn't get much information.

    Thanks.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Dec 2012
    Posts
    101
    Quote Originally Posted by Lee_Jennifer_82 View Post
    Thank you all for the reply. Have any one have done matrix transformation from OpenCV to OpenGL? I am doing by multiplying the opencv matrix by the following:

    |1 0 0 0|
    |0 1 0 0|
    |0 0 1 0|
    |0 0 0 1|

    It makes the y, z axis basis vectors reverse.

    Could any one post some reply regarding this? Recently I did some search in the web about transforming opencv matrix to opengl matrix, but didn't get much information.

    Thanks.
    So sorry for my mistake. The matrix should be as follows:

    |1 0 0 0|
    |0 -1 0 0|
    |0 0 -1 0|
    |0 0 0 1|

  8. #8
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,167

  9. #9
    Junior Member Regular Contributor
    Join Date
    Dec 2012
    Posts
    101
    Thanks for the provided link. I am clear now about the coordinate systems in opencv and opengl. But the way I could make it work right is as follows:

    1)First, post multiply the above mentioned unit matrix ( Y and Z negated) with the opencv matrix, [M'] = [M]*[U];

    2)Then, pre-multiply the above-mentioned unit matrix with the result from the above step, [M''] = [U]*[M'];


    I don't have enough justification why it needs me to work two steps. Only pre-multiplication of the unit matrix with opencv matrix is supposed give the correct result.

    Could any one explain a bit or help me identify my mistake.

    Thanks

  10. #10
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,167
    Quote Originally Posted by Lee_Jennifer_82 View Post
    ...the way I could make it work right is as follows:

    1)First, post multiply the above mentioned unit matrix ( Y and Z negated) with the opencv matrix, [M'] = [M]*[U];

    2)Then, pre-multiply the above-mentioned unit matrix with the result from the above step, [M''] = [U]*[M'];

    I don't have enough justification why it needs me to work two steps.
    It sounds like someone/something is telling you this should be two steps. Who/what is stating that?

    You're saying:

    [M''] = [U]*[M]*[U]

    where M is an OpenCV matrix and U is a mating transform to convert between GL and CV. It happens to be symmetric so it converts both GL->CV and CV->GL. So:

    [GLstuff2] = [M''] * [GLstuff1]

    Inferring from your post, I think we're just talking about a general formula for plugging an OpenCV matrix into an OpenGL matrix computation. That said, I've not worked with OpenCV before.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •