Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 38 ยท Kinematics

Rotations and Transforms

Describe position and orientation with vectors, rotation matrices, homogeneous transforms, Euler angles and quaternions, and chain frames in NumPy.

To move a gripper onto a cup you need to say where the cup is relative to the gripper, relative to the base, relative to the room. Every one of these statements is about a coordinate frame, and moving between frames is done with rotations and translations. This lesson gives you the tool every later lesson uses: the homogeneous transform, a single matrix that holds both orientation and position.

Points, vectors and frames

A frame is an origin plus three perpendicular axes. A point p has different coordinates in different frames, though it is the same physical point. We write p_A for the coordinates of p in frame A. A frame B can be described relative to A by two things: where B's origin is (a translation) and how B's axes are turned (a rotation).

In 2D a rotation by angle ฮธ is a 2x2 matrix:

R(ฮธ) = [[cos ฮธ, -sin ฮธ], [sin ฮธ, cos ฮธ]]

Multiplying a vector by it rotates the vector counter-clockwise by ฮธ. Rotation matrices have useful properties: columns are unit length and perpendicular (so Rโปยน = Rแต€), and the determinant is +1.

Python Rotating points in 2D

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Rotations in 3D

In 3D there are three basic rotations, about the x, y and z axes:

Python
Rx(a) = [[1, 0, 0], [0, cos a, -sin a], [0, sin a, cos a]]
Ry(a) = [[cos a, 0, sin a], [0, 1, 0], [-sin a, 0, cos a]]
Rz(a) = [[cos a, -sin a, 0], [sin a, cos a, 0], [0, 0, 1]]

Rotations combine by matrix multiplication, and order matters: turning 90 degrees about x then about z does not give the same result as the reverse order. Multiplying R = Rz @ Ry @ Rx means "rotate about the fixed x axis first, then y, then z" when you think in fixed axes.

Python Rotation order matters

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Homogeneous transforms

A rotation plus a translation is p_A = R p_B + t. To chain several of these you would have to nest them, which gets messy. The trick is to add a 1 to the vector (a homogeneous coordinate) and use a single 4x4 matrix (3x3 in 2D):

Text
T = [[ R   t ],
     [ 0 0 0 1 ]]

Now [p_A; 1] = T @ [p_B; 1]. Chaining frames becomes multiplication: if T_AB places frame B in A and T_BC places C in B, then T_AC = T_AB @ T_BC. The inverse is also simple: Tโปยน = [[Rแต€, -Rแต€ t], [0, 1]].

flowchart LR
    W["World frame"] -->|"T_WB"| B["Base frame"]
    B -->|"T_BA"| A["Arm tip frame"]
    A -->|"T_AG"| G["Gripper frame"]
    W -.->|"T_WG = T_WB @ T_BA @ T_AG"| G

Multiply left to right along the chain to get a frame's pose in the world.

Python Chaining frames: where is the cup in the world?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The base is turned 90 degrees, so "forward" for the base points along world +y; that is why the cup lands at y = 1.2 + 1 = 2.2 and x = 2.

Euler angles, axis-angle and quaternions

A 3x3 rotation matrix uses nine numbers for three degrees of freedom. Other representations are more compact:

  • Euler angles (roll, pitch, yaw) are three intuitive angles, but they depend on a chosen convention and suffer gimbal lock: at pitch = 90 degrees two axes line up and one degree of freedom is lost.
  • Axis-angle stores a unit axis and an angle (4 numbers, or a 3-vector whose length is the angle).
  • Quaternions (w, x, y, z) with unit length represent any rotation with no gimbal lock, interpolate smoothly (slerp) and are cheap to compose. They are the standard in flight software and ROS messages.
Python Axis-angle to quaternion to matrix

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Use matrices or homogeneous transforms for chaining frames and quaternions for storing and interpolating orientations.

Common mistakes

  • Multiplying in the wrong order. Write each transform as T_target_source, so neighbors in the chain cancel names: T_AB @ T_BC = T_AC.
  • Mixing degrees and radians. NumPy trig uses radians.
  • Mixing up active and passive views: rotating a point versus rotating the frame (which uses the transpose).
  • Forgetting the homogeneous 1 for points (and using 0 for pure directions, which ignore translation).

You are now ready to build a robot arm from transforms in Forward Kinematics.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the inverse of a rotation matrix R?

    Rotation matrices are orthogonal, so the inverse is the transpose, which is cheap and numerically stable.
  2. 2. If T_AB places frame B in frame A and T_BC places C in B, what is T_AC?

    Chain neighbors left to right: T_AC = T_AB @ T_BC.
  3. 3. Why do robot libraries often store orientation as a quaternion?

    Unit quaternions use four numbers, have no singularity and can be interpolated with slerp.
  4. 4. Do two 3D rotations about different axes commute (give the same result in either order)?

    In 2D all rotations share one axis and commute, but in 3D the order matters in general.

Summary

  • A frame is an origin and three axes; the same point has different coordinates in different frames.
  • Rotation matrices are orthogonal with determinant 1; their inverse is the transpose.
  • A 4x4 homogeneous transform holds rotation and translation, and chaining frames is matrix multiplication.
  • Euler angles are intuitive but have gimbal lock; quaternions are compact and singularity-free.

Next: Forward Kinematics