3D Transformations

3D Transformations

3D Rotations

  • Rotation matrices
  • Euler angles
  • Three rotations about x-, y- and z-axis
  • 3D homogeneous and affine transformations
  • Euler angle problems – “gimbal lock”

Recap: 2D Rotation

  • Homogenous transformation:
    [x y]=[cosθamp;sinθ sinθamp;cosθ][x y]\begin{bmatrix} x' \ y' \end{bmatrix} = \begin{bmatrix} cos \theta & -sin \theta \ sin \theta & cos \theta \end{bmatrix} \begin{bmatrix} x \ y \end{bmatrix}

    [x y 1]=[cosθamp;sinθamp;0 sinθamp;cosθamp;0 0amp;0amp;1][x y 1]\begin{bmatrix} x' \ y' \ 1 \end{bmatrix} = \begin{bmatrix} cos \theta & -sin \theta & 0 \ sin \theta & cos \theta & 0 \ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \ y \ 1 \end{bmatrix}

  • (x', y') > (x, y)

  • θ\theta is a positive angle along the counter-clockwise direction

3D Coordinate System Conventions

  • Positive Z direction for left-handed coordinates.
  • Positive Z direction for right-handed coordinates.
  • We use right-handed coordinates unless otherwise noted.

3D Rotation Conventions

  • Right-hand screw rule:
    • Thumb aligns with axis rotated about.
    • Other fingers indicate positive rotation.
  • For right-handed coordinates.
  • 2D Rotation about origin.
  • 3D Rotation about an axis or arbitrary line.
  • Positive angle along the counter-clockwise direction.

3D Rotations about Z-axis

  • Find matrix for a positive rotation of θ\theta about the z-axis.

    [x y z]=[cosθamp;sinθamp;0 sinθamp;cosθamp;0 0amp;0amp;1][x y z]\begin{bmatrix} x' \ y' \ z' \end{bmatrix} = \begin{bmatrix} cos \theta & -sin \theta & 0 \ sin \theta & cos \theta & 0 \ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix}

  • (x', y') > (x, y)

  • (x', y', z') > (x, y, z)

  • The point only moves in the X-Y plane that is orthogonal to Z axis, z value remains the same.

  • Not homogeneous coordinates (z value is not affected).

3D Rotations – by Swapping Axes

  • Rotation about Z-axis:

    [z x y]=[cosθamp;sinθamp;0 sinθamp;cosθamp;0 0amp;0amp;1][z x y]\begin{bmatrix} z' \ x' \ y' \end{bmatrix} = \begin{bmatrix} cos \theta & -sin \theta & 0 \ sin \theta & cos \theta & 0 \ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} z \ x \ y \end{bmatrix}

  • xz,yx,zyx \rightarrow z, y \rightarrow x, z \rightarrow y

  • Final look of the rotation matrix about Y axis:

    [x y z]=[cosθamp;0amp;sinθ 0amp;1amp;0 sinθamp;0amp;cosθ][x y z]\begin{bmatrix} x' \ y' \ z' \end{bmatrix} = \begin{bmatrix} cos \theta & 0 & sin \theta \ 0 & 1 & 0 \ -sin \theta & 0 & cos \theta \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix}

Reordering the Matrix
Step 1: Rearrange the Input Columns
  • The input vector order changes from:

    [z x y]\begin{bmatrix} z \ x \ y \end{bmatrix}

  • To achieve this:

    • The 1st column of the matrix (corresponding to z) becomes the 3rd column.
    • The 2nd column of the matrix (corresponding to x) becomes the 1st column.
    • The 3rd column of the matrix (corresponding to y) becomes the 2nd column.
  • This yields the Intermediate Matrix:

    IntermediateMatrix=[cosθamp;0amp;sinθ 0amp;1amp;0 sinθamp;0amp;cosθ]Intermediate Matrix = \begin{bmatrix} cos \theta & 0 & -sin \theta \ 0 & 1 & 0 \ sin \theta & 0 & cos \theta \end{bmatrix}

Step 2: Rearrange the Output Rows
  • The output vector order changes from:

    [z x y]to[x y z]\begin{bmatrix} z' \ x' \ y' \end{bmatrix} to \begin{bmatrix} x' \ y' \ z' \end{bmatrix}

  • To achieve this:

    • The 1st row of the matrix (corresponding to z') becomes the 3rd row.
    • The 2nd row of the matrix (corresponding to x') becomes the 1st row.
    • The 3rd row of the matrix (corresponding to y') becomes the 2nd row.
  • This yields the Final Matrix:

    FinalMatrix=[cosθamp;0amp;sinθ 0amp;1amp;0 sinθamp;0amp;cosθ]Final Matrix = \begin{bmatrix} cos \theta & 0 & sin \theta \ 0 & 1 & 0 \ -sin \theta & 0 & cos \theta \end{bmatrix}

  • Rotation about X-axis:

    Rx(θ)=[1amp;0amp;0 0amp;cosθamp;sinθ 0amp;sinθamp;cosθ]R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \ 0 & cos \theta & -sin \theta \ 0 & sin \theta & cos \theta \end{bmatrix}

  • Hints: yz,zx,xyy \rightarrow z, z \rightarrow x, x \rightarrow y

3D Rotation Matrices

  • Rotation about Y-axis:

    Ry(θ)=[cosθamp;0amp;sinθ 0amp;1amp;0 sinθamp;0amp;cosθ]R_y(\theta) = \begin{bmatrix} cos \theta & 0 & sin \theta \ 0 & 1 & 0 \ -sin \theta & 0 & cos \theta \end{bmatrix}

  • Rotation about X-axis:

    Rx(θ)=[1amp;0amp;0 0amp;cosθamp;sinθ 0amp;sinθamp;cosθ]R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \ 0 & cos \theta & -sin \theta \ 0 & sin \theta & cos \theta \end{bmatrix}

  • Rotation about Z-axis:

    Rz(θ)=[cosθamp;sinθamp;0 sinθamp;cosθamp;0 0amp;0amp;1]R_z(\theta) = \begin{bmatrix} cos \theta & -sin \theta & 0 \ sin \theta & cos \theta & 0 \ 0 & 0 & 1 \end{bmatrix}

  • The rows with “1” preserve the values of related components.

    • e.g., z component of a point does not change after the point rotated about z axis

Euler Angles

  • We need 3 angles to describe the orientation of a rigid body.

  • Number of possible rotations:

    • XXX, XXY, XXZ, XYX, XYY, XYZ, XZX, XZY, XZZ,
    • YXX, YXY, YXZ, YYX, YYY, YYZ, YZX, YZY, YZZ,
    • ZXX, ZXY, ZXZ, ZYX, ZYY, ZYZ, ZZX, ZZY, ZZZ
  • Generates an arbitrary rotation matrix (rotation about an arbitrary axis passing through the origin).

  • Simple idea: use an ordered combination of rotations about the x-, y- and z-axes, e.g. first X, then Y then Z (all variations used).

  • NB: order matters!

    R=R<em>z(γ)R</em>y(β)Rx(α)R = R<em>z(\gamma)R</em>y(\beta)R_x(\alpha)

3D Rotation Strangeness

  • Suitable (ordered) combination of rotations about any two axes can generate any 3D rotation.

    R<em>z(90°)=R</em>x(90°)R<em>y(90°)R</em>x(90°)R<em>z(90^\degree) = R</em>x(90^\degree)R<em>y(90^\degree)R</em>x(-90^\degree)

    R<em>z(θ)=R</em>x(90°)R<em>y(θ)R</em>x(90°)R<em>z(\theta) = R</em>x(90^\degree)R<em>y(\theta)R</em>x(-90^\degree)

Steps to combine the rotations
  1. Represent the rotation as matrices

    • Rotation Matrix around X-axis (Rx(θ)R_x(\theta)) :

      Rx(θ)=[1amp;0amp;0 0amp;cosθamp;sinθ 0amp;sinθamp;cosθ]R_x(\theta) = \begin{bmatrix} 1 &amp; 0 &amp; 0 \ 0 &amp; cos \theta &amp; -sin \theta \ 0 &amp; sin \theta &amp; cos \theta \end{bmatrix}

    • Rotation Matrix around Y-axis (Ry(θ)R_y(\theta)) :

      Ry(θ)=[cosθamp;0amp;sinθ 0amp;1amp;0 sinθamp;0amp;cosθ]R_y(\theta) = \begin{bmatrix} cos \theta &amp; 0 &amp; sin \theta \ 0 &amp; 1 &amp; 0 \ -sin \theta &amp; 0 &amp; cos \theta \end{bmatrix}

  2. Define the Rotations

    • First rotation: Rx(90°)R_x(-90^\degree)

      Rx(90°)=[1amp;0amp;0 0amp;0amp;1 0amp;1amp;0]R_x(-90^\degree) = \begin{bmatrix} 1 &amp; 0 &amp; 0 \ 0 &amp; 0 &amp; 1 \ 0 &amp; -1 &amp; 0 \end{bmatrix}

    • Second rotation: Ry(90°)R_y(90^\degree)

      Ry(90°)=[0amp;0amp;1 0amp;1amp;0 1amp;0amp;0]R_y(90^\degree) = \begin{bmatrix} 0 &amp; 0 &amp; 1 \ 0 &amp; 1 &amp; 0 \ -1 &amp; 0 &amp; 0 \end{bmatrix}

  3. Combine the Rotations

    • The combined rotation matrix R<em>combinedR<em>{combined} is: R</em>combined=R<em>x(90°)R</em>y(90°)Rx(90°)R</em>{combined} = R<em>x(90^\degree) \cdot R</em>y(90^\degree) \cdot R_x(-90^\degree)

      • Compute R<em>y(90°)R</em>x(90°)R<em>y(90^\degree) \cdot R</em>x(-90^\degree)

        [0amp;0amp;1 0amp;1amp;0 1amp;0amp;0][1amp;0amp;0 0amp;0amp;1 0amp;1amp;0]=[0amp;1amp;0 0amp;0amp;1 1amp;0amp;0]\begin{bmatrix} 0 &amp; 0 &amp; 1 \ 0 &amp; 1 &amp; 0 \ -1 &amp; 0 &amp; 0 \end{bmatrix} \cdot \begin{bmatrix} 1 &amp; 0 &amp; 0 \ 0 &amp; 0 &amp; 1 \ 0 &amp; -1 &amp; 0 \end{bmatrix} = \begin{bmatrix} 0 &amp; -1 &amp; 0 \ 0 &amp; 0 &amp; 1 \ -1 &amp; 0 &amp; 0 \end{bmatrix}

      • Compute R<em>x(90°)(R</em>y(90°)Rx(90°))R<em>x(90^\degree) \cdot (R</em>y(90^\degree) \cdot R_x(-90^\degree))
        [1amp;0amp;0 0amp;0amp;1 0amp;1amp;0][0amp;1amp;0 0amp;0amp;1 1amp;0amp;0]=[0amp;1amp;0 1amp;0amp;0 0amp;0amp;1]\begin{bmatrix} 1 &amp; 0 &amp; 0 \ 0 &amp; 0 &amp; -1 \ 0 &amp; 1 &amp; 0 \end{bmatrix} \cdot \begin{bmatrix} 0 &amp; -1 &amp; 0 \ 0 &amp; 0 &amp; 1 \ -1 &amp; 0 &amp; 0 \end{bmatrix} = \begin{bmatrix} 0 &amp; -1 &amp; 0 \ 1 &amp; 0 &amp; 0 \ 0 &amp; 0 &amp; 1 \end{bmatrix}

  4. Apply the Combined Rotation

    • Let's assume the initial point is P=[x,y,z]TP = [x, y, z]^T. After applying R<em>combinedR<em>{combined}, the final point becomes: P=R</em>combinedPP' = R</em>{combined} \cdot P

    • For an example point [1,0,0][1, 0, 0]:

      P=[0amp;1amp;0 1amp;0amp;0 0amp;0amp;1][1 0 0]=[0 1 0]P' = \begin{bmatrix} 0 &amp; -1 &amp; 0 \ 1 &amp; 0 &amp; 0 \ 0 &amp; 0 &amp; 1 \end{bmatrix} \cdot \begin{bmatrix} 1 \ 0 \ 0 \end{bmatrix} = \begin{bmatrix} 0 \ 1 \ 0 \end{bmatrix}

Euler Angle Troubles

  • Gimbal lock occurs when one axis of rotation lines up with another, losing a degree of freedom.
Gimbal Lock
  • p=R<em>z(γ)R</em>y(β)Rx(α)pp' = R<em>z(\gamma)R</em>y(\beta)R_x(\alpha)p
  • β=90°\beta = 90^\degree
  • The rotation axis of R<em>xR<em>x is made to line up with the rotation axis of R</em>zR</em>z. We are no longer able to move in the direction that RxR_x previously enabled us to.

Homogeneous Coordinates in 3D

  • Add a “1” to the last coordinate to make translation a linear operation (i.e. a matrix multiplication).

    [p<em>1 p</em>2 p<em>3]=[p</em>1 p<em>2 p</em>3]+[t<em>1 t</em>2 t<em>3]\begin{bmatrix} p'<em>1 \ p'</em>2 \ p'<em>3 \end{bmatrix} = \begin{bmatrix} p</em>1 \ p<em>2 \ p</em>3 \end{bmatrix} + \begin{bmatrix} t<em>1 \ t</em>2 \ t<em>3 \end{bmatrix}[p</em>1 p<em>2 p</em>3 1]=[1amp;0amp;0amp;t<em>1 010t</em>2 0amp;0amp;1amp;t<em>3 0001][p</em>1 p<em>2 p</em>3 1]=[p<em>1+t</em>1 p<em>2+t</em>2 p<em>3+t</em>3 1]\begin{bmatrix} p'</em>1 \ p'<em>2 \ p'</em>3 \ 1 \end{bmatrix} = \begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; t<em>1 \ 0 & 1 & 0 & t</em>2 \ 0 &amp; 0 &amp; 1 &amp; t<em>3 \ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} p</em>1 \ p<em>2 \ p</em>3 \ 1 \end{bmatrix} = \begin{bmatrix} p<em>1 + t</em>1 \ p<em>2 + t</em>2 \ p<em>3 + t</em>3 \ 1 \end{bmatrix}

  • Represent T as a matrix.

3D Affine Transformations

  • Recall 2D:

    [p<em>1 p</em>2 1]=[m<em>11m</em>12amp;m<em>13 m</em>21amp;m<em>22m</em>23 0amp;0amp;1][p<em>1 p</em>2 1]\begin{bmatrix} p'<em>1 \ p'</em>2 \ 1 \end{bmatrix} = \begin{bmatrix} m<em>{11} & m</em>{12} &amp; m<em>{13} \ m</em>{21} &amp; m<em>{22} & m</em>{23} \ 0 &amp; 0 &amp; 1 \end{bmatrix} \begin{bmatrix} p<em>1 \ p</em>2 \ 1 \end{bmatrix}

  • So in 3D:

    [p<em>1 p</em>2 p<em>3 1]=[m</em>11amp;m<em>12m</em>13amp;m<em>14 m</em>21amp;m<em>22m</em>23amp;m<em>24 m</em>31amp;m<em>32m</em>33amp;m<em>34 0001][p</em>1 p<em>2 p</em>3 1]\begin{bmatrix} p'<em>1 \ p'</em>2 \ p'<em>3 \ 1 \end{bmatrix} = \begin{bmatrix} m</em>{11} &amp; m<em>{12} & m</em>{13} &amp; m<em>{14} \ m</em>{21} &amp; m<em>{22} & m</em>{23} &amp; m<em>{24} \ m</em>{31} &amp; m<em>{32} & m</em>{33} &amp; m<em>{34} \ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} p</em>1 \ p<em>2 \ p</em>3 \ 1 \end{bmatrix}

  • 12 degrees of freedom

  • 6 degrees of freedom

Affine Transformation in Homogeneous Coordinates

  • Example: Transformation Decomposition

    Given Transformation Matrix

    T=[2amp;0amp;0amp;5 0amp;3amp;0amp;2 0amp;0amp;4amp;3 0amp;0amp;0amp;1]T = \begin{bmatrix} 2 &amp; 0 &amp; 0 &amp; 5 \ 0 &amp; 3 &amp; 0 &amp; 2 \ 0 &amp; 0 &amp; 4 &amp; -3 \ 0 &amp; 0 &amp; 0 &amp; 1 \end{bmatrix}

    Components:

    1. Scaling:
      • The diagonal elements [2, 3, 4] indicate scaling along the x, y, and z axes, respectively.
    2. Translation:
      • The last column [5, 2, -3] represents a translation by (tx = 5, ty = 2, tz = −3).
    3. No Rotation or Shearing:
      • The off-diagonal elements are all 0, indicating no rotation or shearing.

Applying to a Point

  • Given a point [1,1,1,1]T[1, 1, 1, 1]^T:

    T[1 1 1 1]=[21+01+01+51 01+31+01+21 01+01+41+(3)1 1]=[7 5 1 1]T \cdot \begin{bmatrix} 1 \ 1 \ 1 \ 1 \end{bmatrix} = \begin{bmatrix} 2 \cdot 1 + 0 \cdot 1 + 0 \cdot 1 + 5 \cdot 1 \ 0 \cdot 1 + 3 \cdot 1 + 0 \cdot 1 + 2 \cdot 1 \ 0 \cdot 1 + 0 \cdot 1 + 4 \cdot 1 + (-3) \cdot 1 \ 1 \end{bmatrix} = \begin{bmatrix} 7 \ 5 \ 1 \ 1 \end{bmatrix}

Compound Transformations

  • Homogeneous transformations in 3D are just as easily concatenated as in 2D:

    p=T<em>3T</em>2T1pp' = T<em>3 T</em>2 T_1 p

  • Remember that the order of operations matters in general:

    T<em>1T</em>2T<em>2T</em>1T<em>1 T</em>2 \neq T<em>2 T</em>1

Order of Transformations

2D Local/Global Coordinates

  • Transformation matrix that combines rotation and translation.

3D Local/Global Coordinates

  • p<em>world=T</em>1pwallep<em>{world} = T</em>1 p_{wall_e}
  • p~<em>world=R</em>1p~<em>walle+t</em>1\tilde{p}<em>{world} = R</em>1 \tilde{p}<em>{wall_e} + t</em>1

Coordinate Transformations

  • Hand coordinates to arm coordinates: p<em>arm=T</em>3phandp<em>{arm} = T</em>3 p_{hand}
  • Arm coordinates to Wall-e coordinates: p<em>walle=T</em>2parmp<em>{wall_e} = T</em>2 p_{arm}
  • Wall-e coordinates to world coordinates: p<em>world=T</em>1pwallep<em>{world} = T</em>1 p_{wall_e}
  • Hand coordinates to world coordinates: p<em>world=T</em>1T<em>2T</em>3phandp<em>{world} = T</em>1 T<em>2 T</em>3 p_{hand}
  • Order of Transformations is important. These transformations are in a hierarchy.
  • For example, if the hand moves, only the T3T_3 matrix would change because the hand is relative to the arm. The other transformations will remain the same.