# Thread: Need some clarification on transformation matrices

1. ## 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.

Thanks.

2. 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. Originally Posted by Lee_Jennifer_82
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.)

4. Originally Posted by Dark Photon
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. 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. 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. Originally Posted by Lee_Jennifer_82
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. 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

9. Originally Posted by Lee_Jennifer_82
...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
•