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:
    \begin{bmatrix} x' \ y' \end{bmatrix} = \begin{bmatrix} cos \theta & -sin \theta \ sin \theta & cos \theta \end{bmatrix} \begin{bmatrix} x \ y \end{bmatrix}

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

    \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:

    \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}

  • x \rightarrow z, y \rightarrow x, z \rightarrow y

  • Final look of the rotation matrix about Y axis:

    \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:

    \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:

    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:

    \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:

    Final Matrix = \begin{bmatrix} cos \theta & 0 & sin \theta \ 0 & 1 & 0 \ -sin \theta & 0 & cos \theta \end{bmatrix}

  • Rotation about X-axis:

    R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \ 0 & cos \theta & -sin \theta \ 0 & sin \theta & cos \theta \end{bmatrix}

  • Hints: y \rightarrow z, z \rightarrow x, x \rightarrow y

3D Rotation Matrices

  • Rotation about Y-axis:

    R_y(\theta) = \begin{bmatrix} cos \theta & 0 & sin \theta \ 0 & 1 & 0 \ -sin \theta & 0 & cos \theta \end{bmatrix}

  • Rotation about X-axis:

    R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \ 0 & cos \theta & -sin \theta \ 0 & sin \theta & cos \theta \end{bmatrix}

  • Rotation about Z-axis:

    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 = Rz(\gamma)Ry(\beta)R_x(\alpha)

3D Rotation Strangeness

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

    Rz(90^\degree) = Rx(90^\degree)Ry(90^\degree)Rx(-90^\degree)

    Rz(\theta) = Rx(90^\degree)Ry(\theta)Rx(-90^\degree)

Steps to combine the rotations

  1. Represent the rotation as matrices

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

      R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \ 0 & cos \theta & -sin \theta \ 0 & sin \theta & cos \theta \end{bmatrix}

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

      R_y(\theta) = \begin{bmatrix} cos \theta & 0 & sin \theta \ 0 & 1 & 0 \ -sin \theta & 0 & cos \theta \end{bmatrix}

  2. Define the Rotations

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

      R_x(-90^\degree) = \begin{bmatrix} 1 & 0 & 0 \ 0 & 0 & 1 \ 0 & -1 & 0 \end{bmatrix}

    • Second rotation: R_y(90^\degree)

      R_y(90^\degree) = \begin{bmatrix} 0 & 0 & 1 \ 0 & 1 & 0 \ -1 & 0 & 0 \end{bmatrix}

  3. Combine the Rotations

    • The combined rotation matrix R{combined} is: R{combined} = Rx(90^\degree) \cdot Ry(90^\degree) \cdot R_x(-90^\degree)

      • Compute Ry(90^\degree) \cdot Rx(-90^\degree)

        \begin{bmatrix} 0 & 0 & 1 \ 0 & 1 & 0 \ -1 & 0 & 0 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 \ 0 & 0 & 1 \ 0 & -1 & 0 \end{bmatrix} = \begin{bmatrix} 0 & -1 & 0 \ 0 & 0 & 1 \ -1 & 0 & 0 \end{bmatrix}

      • Compute Rx(90^\degree) \cdot (Ry(90^\degree) \cdot R_x(-90^\degree))
        \begin{bmatrix} 1 & 0 & 0 \ 0 & 0 & -1 \ 0 & 1 & 0 \end{bmatrix} \cdot \begin{bmatrix} 0 & -1 & 0 \ 0 & 0 & 1 \ -1 & 0 & 0 \end{bmatrix} = \begin{bmatrix} 0 & -1 & 0 \ 1 & 0 & 0 \ 0 & 0 & 1 \end{bmatrix}

  4. Apply the Combined Rotation

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

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

      P' = \begin{bmatrix} 0 & -1 & 0 \ 1 & 0 & 0 \ 0 & 0 & 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' = Rz(\gamma)Ry(\beta)R_x(\alpha)p
  • \beta = 90^\degree
  • The rotation axis of Rx is made to line up with the rotation axis of Rz. We are no longer able to move in the direction that R_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).

    \begin{bmatrix} p'1 \ p'2 \ p'3 \end{bmatrix} = \begin{bmatrix} p1 \ p2 \ p3 \end{bmatrix} + \begin{bmatrix} t1 \ t2 \ t3 \end{bmatrix} \begin{bmatrix} p'1 \ p'2 \ p'3 \ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & t1 \ 0 & 1 & 0 & t2 \ 0 & 0 & 1 & t3 \ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} p1 \ p2 \ p3 \ 1 \end{bmatrix} = \begin{bmatrix} p1 + t1 \ p2 + t2 \ p3 + t3 \ 1 \end{bmatrix}

  • Represent T as a matrix.

3D Affine Transformations

  • Recall 2D:

    \begin{bmatrix} p'1 \ p'2 \ 1 \end{bmatrix} = \begin{bmatrix} m{11} & m{12} & m{13} \ m{21} & m{22} & m{23} \ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} p1 \ p2 \ 1 \end{bmatrix}

  • So in 3D:

    \begin{bmatrix} p'1 \ p'2 \ p'3 \ 1 \end{bmatrix} = \begin{bmatrix} m{11} & m{12} & m{13} & m{14} \ m{21} & m{22} & m{23} & m{24} \ m{31} & m{32} & m{33} & m{34} \ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} p1 \ p2 \ p3 \ 1 \end{bmatrix}

  • 12 degrees of freedom

  • 6 degrees of freedom

Affine Transformation in Homogeneous Coordinates

  • Example: Transformation Decomposition

    Given Transformation Matrix

    T = \begin{bmatrix} 2 & 0 & 0 & 5 \ 0 & 3 & 0 & 2 \ 0 & 0 & 4 & -3 \ 0 & 0 & 0 & 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:

    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' = T3 T2 T_1 p

  • Remember that the order of operations matters in general:

    T1 T2 \neq T2 T1

Order of Transformations

2D Local/Global Coordinates

  • Transformation matrix that combines rotation and translation.

3D Local/Global Coordinates

  • p{world} = T1 p_{wall_e}
  • \tilde{p}{world} = R1 \tilde{p}{wall_e} + t1

Coordinate Transformations

  • Hand coordinates to arm coordinates: p{arm} = T3 p_{hand}
  • Arm coordinates to Wall-e coordinates: p{wall_e} = T2 p_{arm}
  • Wall-e coordinates to world coordinates: p{world} = T1 p_{wall_e}
  • Hand coordinates to world coordinates: p{world} = T1 T2 T3 p_{hand}
  • Order of Transformations is important. These transformations are in a hierarchy.
  • For example, if the hand moves, only the T_3 matrix would change because the hand is relative to the arm. The other transformations will remain the same.