thalm
thalm

Reputation: 2920

How to convert a 4x4 matrix transformation to another coordinate system?

Is there a general method to convert a matrix transformation from one coordinate system to another, so that the resulting transformation looks the same on screen?

For example, there are some transformations in a coordinate system with X right, Y up, and Z toward the viewer. And they need to be converted to a coordinate system with X right, Y away from the viewer, and Z up.

enter image description here

What would be the operation that needs to be performed for each matrix so that the transformations look the same in the other coordinate system? And is there a general way to construct this operation given the source and destination basis vectors?

Upvotes: 0

Views: 988

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112342

This is a rotation around the x-axis by 90 degrees

┌                      ┐
│ 1   0       0      0 │
│ 0  cos(θ) -sin(θ)  0 │
│ 0  sin(θ)  cos(θ)  0 │
│ 0   0       0      1 │
└                      ┘

... where cos(+/-90) = 0, sin(+/-90) = +/-1

┌               ┐
│ 1   0   0   0 │
│ 0   0  -1   0 │
│ 0   1   0   0 │
│ 0   0   0   1 │
└               ┘

or by -90 degrees

┌               ┐
│ 1   0   0   0 │
│ 0   0   1   0 │
│ 0  -1   0   0 │
│ 0   0   0   1 │
└               ┘

I am not sure which one will help in your case. It's one of these things where, according to Murphy's law, you are doing it the wrong way round the first time.

See: 3D Transformation

To convert the transformation formulated for the old coordinate system T into one for the new coordinate system T', we can write by using the above rotation R

T' = R-1 × T × R

The result is a transformation that converts a point in the new coordinate system back to the old one, then applies the original transformation and finally converts the result into the new coordinate system again.

Upvotes: 1

Scott Settlemier
Scott Settlemier

Reputation: 22

You just need to compose that matrix that does something you like with the appropriate coordinate transformation matrices. If you have a system A and some operation X on pts in that system you like, but you encode your points in system B for the same space and want to do what X does in space, then you can just apply X'=inv(M)XM where M is the coordinate transformation from B to A.

Upvotes: 1

Related Questions