Skip to main content
Adding note on fast inversion via transpose
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.


You can use this same logic to work with untransformed vectors already in the new coordinate system: just convert them back to the old coordinate system (using the inverse of matrix \$\Bbb C\$ above, \$\Bbb C^{-1}\$), use the transformation matrix from the old system (\$\Bbb M\$), and then convert back:

$$\begin{align} \vec v_\text{transformed-new} &= \Bbb C \times \vec v_\text{transformed-old} \\ &= \Bbb C \times (\Bbb M \times \vec v_\text{untransformed-old}) \\ &= (\Bbb C \Bbb M) \times (\Bbb C^{-1} \times \vec v_\text{untransformed-new}) \\ &= (\Bbb C \Bbb M \Bbb C^{-1}) \times \vec v_\text{untransformed-new} \\ \end{align}$$

So, your matrix that does the same job as \$\Bbb M\$ but in the new coordinate system is just \$\Bbb M_\text{new} = \Bbb C \Bbb M \Bbb C^{-1}\$.

Since your coordinate transformation is pure rotation/reflection - no scaling/shearing - the inverse of \$\Bbb C\$ is just its transpose (making its rows into columns and vice versa):

$$\Bbb C^{-1} = \Bbb C^T = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.


You can use this same logic to work with untransformed vectors already in the new coordinate system: just convert them back to the old coordinate system (using the inverse of matrix \$\Bbb C\$ above, \$\Bbb C^{-1}\$), use the transformation matrix from the old system, and then convert back:

$$\begin{align} \vec v_\text{transformed-new} &= \Bbb C \times \vec v_\text{transformed-old} \\ &= \Bbb C \times (\Bbb M \times \vec v_\text{untransformed-old}) \\ &= (\Bbb C \Bbb M) \times (\Bbb C^{-1} \times \vec v_\text{untransformed-new}) \\ &= (\Bbb C \Bbb M \Bbb C^{-1}) \times \vec v_\text{untransformed-new} \\ \end{align}$$

So, your matrix that does the same job as \$\Bbb M\$ but in the new coordinate system is just \$\Bbb M_\text{new} = \Bbb C \Bbb M \Bbb C^{-1}\$.

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.


You can use this same logic to work with untransformed vectors already in the new coordinate system: just convert them back to the old coordinate system (using the inverse of matrix \$\Bbb C\$ above, \$\Bbb C^{-1}\$), use the transformation matrix from the old system (\$\Bbb M\$), and then convert back:

$$\begin{align} \vec v_\text{transformed-new} &= \Bbb C \times \vec v_\text{transformed-old} \\ &= \Bbb C \times (\Bbb M \times \vec v_\text{untransformed-old}) \\ &= (\Bbb C \Bbb M) \times (\Bbb C^{-1} \times \vec v_\text{untransformed-new}) \\ &= (\Bbb C \Bbb M \Bbb C^{-1}) \times \vec v_\text{untransformed-new} \\ \end{align}$$

So, your matrix that does the same job as \$\Bbb M\$ but in the new coordinate system is just \$\Bbb M_\text{new} = \Bbb C \Bbb M \Bbb C^{-1}\$.

Since your coordinate transformation is pure rotation/reflection - no scaling/shearing - the inverse of \$\Bbb C\$ is just its transpose (making its rows into columns and vice versa):

$$\Bbb C^{-1} = \Bbb C^T = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

Adding matrix conversion step
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.


You can use this same logic to work with untransformed vectors already in the new coordinate system: just convert them back to the old coordinate system (using the inverse of matrix \$\Bbb C\$ above, \$\Bbb C^{-1}\$), use the transformation matrix from the old system, and then convert back:

$$\begin{align} \vec v_\text{transformed-new} &= \Bbb C \times \vec v_\text{transformed-old} \\ &= \Bbb C \times (\Bbb M \times \vec v_\text{untransformed-old}) \\ &= (\Bbb C \Bbb M) \times (\Bbb C^{-1} \times \vec v_\text{untransformed-new}) \\ &= (\Bbb C \Bbb M \Bbb C^{-1}) \times \vec v_\text{untransformed-new} \\ \end{align}$$

So, your matrix that does the same job as \$\Bbb M\$ but in the new coordinate system is just \$\Bbb M_\text{new} = \Bbb C \Bbb M \Bbb C^{-1}\$.

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.


You can use this same logic to work with untransformed vectors already in the new coordinate system: just convert them back to the old coordinate system (using the inverse of matrix \$\Bbb C\$ above, \$\Bbb C^{-1}\$), use the transformation matrix from the old system, and then convert back:

$$\begin{align} \vec v_\text{transformed-new} &= \Bbb C \times \vec v_\text{transformed-old} \\ &= \Bbb C \times (\Bbb M \times \vec v_\text{untransformed-old}) \\ &= (\Bbb C \Bbb M) \times (\Bbb C^{-1} \times \vec v_\text{untransformed-new}) \\ &= (\Bbb C \Bbb M \Bbb C^{-1}) \times \vec v_\text{untransformed-new} \\ \end{align}$$

So, your matrix that does the same job as \$\Bbb M\$ but in the new coordinate system is just \$\Bbb M_\text{new} = \Bbb C \Bbb M \Bbb C^{-1}\$.

Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

This is as easy as writing your old coordinates in terms of the new ones.

  • We want +x to map to +x (1, 0, 0)

  • We want +y to map to +z (0, 0, 1)

  • We want +z to map to -y (0, -1, 0)

  • We want the fourth, homogenous coordinate to survive unchanged (0, 0, 0, 1)

So you make those vectors the columns of a coordinate conversion matrix:

$$\Bbb C = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

If you left-multiply this matrix by any homogeneous vector in your old coordinate system, it converts it to the corresponding vector in the new coordinate system:

$$\vec v_{\text{new}} = \Bbb C \times \vec v_{\text{old}}$$

And the same goes for any vector transformed by a transformation matrix \$\Bbb M\$ expressed in your old space:

$$ \vec v_{\text{new}} = \Bbb C \times \vec v_{\text{transformed}} = \Bbb C \times (\Bbb M \times \vec v_{\text{untransformed}})\\ \vec v_{\text{new}} = (\Bbb C \Bbb M) \times \vec v_{\text{untransformed}}$$

So you can multiply any transformation matrix by this coordinate transformation matrix to get a single matrix that does both the original transformation and the coordinate conversion.

If you use the opposite multiplication convention - vector on the left, matrix on the right - then take the transpose of \$\Bbb C\$ (so your destination vectors are the rows instead of the columns) and multiply it on the right instead of the left.