View Full Version : Need some clarification on transformation matrices

Lee_Jennifer_82

06-30-2014, 01:16 PM

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.

Aleksandar

06-30-2014, 01:50 PM

Not even close!

And where is the rotation angle?

Take a look at Appendix F (http://www.glprogramming.com/red/appendixf.html) of the Red Book, or any other 3D graphics book covering the transformations.

Dark Photon

06-30-2014, 06:00 PM

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.)

Carmine

06-30-2014, 06:45 PM

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.

Aleksandar

07-01-2014, 03:41 AM

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.

Lee_Jennifer_82

07-01-2014, 02:16 PM

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.

Lee_Jennifer_82

07-01-2014, 05:42 PM

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|

Dark Photon

07-01-2014, 06:48 PM

OpenCV:

* http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/OWENS/LECT9/node2.html

OpenGL:

* http://www.gamerendering.com/2008/10/05/clip-space/

So yep. Negating Y and Z seems to make sense.

Lee_Jennifer_82

07-01-2014, 09:14 PM

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

Dark Photon

07-02-2014, 06:58 PM

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

Lee_Jennifer_82

07-03-2014, 12:34 PM

Hi Dark Photon, thank you very much again for commenting on my post. I know as a newbie, my question my be too simple to ask. We don't need to consider opencv. Let us consider the two coordinate systems as found in the image attached.

1352

I think the first step i.e. ( [M'] = [M]*[U]) converts any object in coordinate system (a) so that it looks with similar orientation in coordinate system (b).

Next step ([M''] = [U]*[M']) did conversion so that it matches the coordinate system (b) i.e. opengl coordinate system.

I tried on some simple model and it works. But would be happy to hear further justification from you.

Please help with further comments or suggestions.

Dark Photon

07-03-2014, 05:29 PM

I'm sorry. I don't understand your question.

Lee_Jennifer_82

07-04-2014, 12:27 AM

Sorry for the confusion. Let me try to explain again. Suppose I have a rotation matrix in coordinate system (a). I would like to see it in coordinate system (b) but with same orientation as shown in (a). The first step ( [M'] = [M]*[U]) does this. Am I right?

Dark Photon

07-04-2014, 09:39 AM

If I understand your question correctly, yes.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.