#### Archived

This topic is now archived and is closed to further replies.

# Conversion between left and right handed coordinate systems

This topic is 5560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I''m trying to convert my file format (kept in a left handed coordinate system) to render in opengl''s right handed coordiante system, where left hand Coordinate system defined as x, y, z where they point right, up and into the screen and right handed coordinate system defined as x,y, z where they point right, up and away from the screen respectively. Now technically could i multipy all z values by -1 and rotate by the negative amount? Suppose i have some transformations in my file and i want to convert this transformation from left hand to right hand. I dont think scaling it by [1 1 -1] and negating the z translation component works. does anybody know how to convert this properly. I think i''ve seen it on the forums before but the search isn''t working. Thanks for any help.

##### Share on other sites
Does this make any sence:

Let P be a point.
Let W be a transformation in left handed coordnate system.
Let S be a transformation that converts Point P from left to right coordinate systems.

Thus S = | 1 0 0 0 |
| 0 1 0 0 |
| 0 0 -1 0 |
| 0 0 0 1 |

So (P*W) *S = transformed point in right handed coordinate system.

since mutliplicative associativity holds between nxm matricies:

(P*W)*S = P (W*S)

So The product of W and S is W with the thrid column negated. Thus to transform from a transformation from left to right handed coordinate systems we can just negate it''s thrid column.

Is this correct?

##### Share on other sites
Does this make any sence:

Let P be a point.
Let W be a transformation in left handed coordnate system.
Let S be a transformation that converts Point P from left to right coordinate systems.
Thus S =                                   | 1  0  0  0 |                                  | 0  1  0  0 |                                  | 0  0 -1  0 |                                  | 0  0  0  1 |

So (P*W) *S = transformed point in right handed coordinate system.

since mutliplicative associativity holds between nxm matricies:

(P*W)*S = P (W*S)

So The product of W and S is W with the thrid column negated. Thus to transform from a transformation from left to right handed coordinate systems we can just negate it's thrid column.

Is this correct?

[edited by - _walrus on October 31, 2002 4:34:32 PM]

[edited by - _walrus on October 31, 2002 4:35:19 PM]

[edited by - _walrus on October 31, 2002 4:35:44 PM]

##### Share on other sites
Yep, that's correct. Just flip the sign of the third column (for column-major matrices; the third row for row-major matrices) and don't forget to change the winding of your triangles to counter-clockwise (or simply flip the culling mode).

[edited by - Asgard on November 1, 2002 10:43:35 AM]

##### Share on other sites
Great thanks Asgard,

The above method (scaling the thrid column) works on translations, but what about rotation components of the transformation? Rotating about the Z axis is the same for both coordinate system, but the rotations about the y and x axis are negated in the two systems. Will scaling the thrid column address this?

##### Share on other sites
I'm not sure if I understand your question correctly. Basically negating the third column negates the z coordinate of every vector you multiply with the matrix, which is exactly what is needed to convert a vector from left-handed to right-handed coordinates. It doesn't have anything to do with what kind of matrix that is.
Note that, if you have multiple matrices in your file format that might get concatenated somewhere (like a hierarchy with each node having its own matrix), then negating the third column in each of those matrices will not give the desired result (at least, if the number of concatenated matrices is even).
So in general, it's probably best to simply convert all the vertices in your file to right-handed coordinates by setting z' = -z for each vertex and not change any of your matrices. Another option would be to leave the vertices as they are and simply set a left-handed projection matrix when rendering with OpenGL.

[edited by - Asgard on November 1, 2002 4:22:09 PM]

##### Share on other sites
Hey, i guess what i mean can be best illustrated in an example:

suppose i have the following in my file (left handed system):

PUSHTRANSFORMATION W| -1  0  0  0 ||  0  1  0  0 ||  0  0 -1  0 ||  0  0  0  1 |  //where this row holds the translation componentsPOINTS [ vertex data for some points ]POP

All points specified in between PUSH and POP will be affected by the TRANSFORMATION. We see that this transformation W will rotate the points 180 degrees about the y-axis.

Now we apply S to W to tranform to right handed coordinate system where S is
|  1  0  0  0 ||  0  1  0  0 ||  0  0 -1  0 ||  0  0  0  1 |

This product yeilds a tranformation in right handed coordinate system:
| -1  0  0  0 ||  0  1  0  0 ||  0  0  1  0 ||  0  0  0  1 |  //where this row holds the translation

But is this correct? Since in the left handed system we are rotating points about the y-axis 180 degrees? This matrix does not rotate about y-axis 180 degrees.

Intuatively shouldn't we be rotating points about the y-axis at -180 degrees in the right handed system as follows:

in left handed system:
|  cos(180)   0          0          0  ||  0          0          0          0  ||  0          0          cos(180)   0  ||  0          0          0          0  |so the equivalent transform in right handed system would be :|  cos(-180)  0          0          0  ||  0          0          0          0  ||  0          0          cos(-180)  0  ||  0          0          0          0  |

Since cos(-180) = cos(180) we have the same matrix. Therefore using S to convert from one coordinate system to the other when rotation are involved is not adiquate.

I suppose i could tranform all points to get to them to world cooridinates and then apply S to each point, but I would really like to preseve the notaion of localized spaces in my system by transforming local points to right hand system by multipling by S and by converting Transformation by ???(by some process or by multiplying by some Transformation R). Any ideas or comments would be very helpful. Or does anyone know of documentation or books that illustrate how to do this? And thanks Asgard for your help so far.

[edited by - _walrus on November 2, 2002 1:48:06 PM]

[edited by - _walrus on November 2, 2002 1:50:23 PM]

[edited by - _walrus on November 2, 2002 1:55:44 PM]