Search

Search papers and lessons

Coordinate Frame

Level 2 · 11 min read

A coordinate frame is a point called an origin plus three perpendicular axes, and it is the reference that gives a point its numbers, so the same point has different coordinates in different frames.

On this page

  • Colour = topic mix
  • Discrete math
  • Linear algebra
  • Kinematics and dynamics
  • ReadReady to readNot yet

TL;DR

A coordinate frame is a reference for measuring position. It has an origin, which is a chosen point, and a set of axes that start at that origin and point in chosen directions. A point has coordinates only relative to some frame, so the same physical point gets different numbers in different frames. A robot uses many frames at once, one for the room, one for its base, one for each link and sensor, and it converts between them with rotations and shifts.

Builds on: Rotation Matrix · Leads to: Rigid Body Transformation, Visual SLAM

Where it's used

Robot arms. Each link of an arm has its own frame attached to it, so the joint motor only needs to know how one link sits relative to the link before it. To find where the gripper is in the room, the controller chains the frame of each link to the next. The chain of frames is the basis of forward kinematics, which computes the tool position from the joint angles.

Mobile robots and sensors. A lidar or camera mounted on a robot reports what it sees in its own frame. To build a map of the room, the software must move each reading into the world frame, using the robot's current pose. A wrong value for the sensor's mounting offset, which is a fixed transform between frames, shifts every reading by the same error.

Games and 3D software. A character's hand is positioned relative to its arm, the arm relative to the body, and the body relative to the scene. Each of these is a frame, and moving the body moves everything attached to it, without any of the child objects needing new numbers. Scene graphs in game engines store exactly this parent-child structure.

How it works

Take a two-dimensional world frame WW with its origin at (0,0)(0, 0), x pointing right and y pointing up. Place a second frame BB with its origin at (3,1)(3, 1) in WW, and turn its axes 90 degrees counterclockwise. In BB, the x-axis points up in WW, and the y-axis points left in WW. Now trace one point through the two frames.

  1. Name the point in BB. The point pp is one unit along BB's x-axis, so its coordinates in BB are (1,0)(1, 0). Check: this is the address of the point in the frame BB, nothing more.
  2. Turn the offset to the world directions. One unit along BB's x-axis is one unit along WW's y-axis after the 90 degree turn, so the offset in WW directions is (0,1)(0, 1). Check: the rotation maps (1,0)(1, 0) to (0,1)(0, 1).
  3. Move the origin. BB's origin sits at (3,1)(3, 1) in WW, so add it: (0,1)+(3,1)=(3,2)(0, 1) + (3, 1) = (3, 2). Check: the point is 3 units right and 2 units up from WW's origin.
  4. Read the same point in WW. The point has coordinates (3,2)(3, 2) in WW and (1,0)(1, 0) in BB. Both are correct, and they are two addresses for one place.
  5. Repeat for a second point. The point (0,1)(0, 1) in BB is one unit along BB's y-axis. Turning it gives (−1,0)(-1, 0) in WW, and adding the origin gives (2,1)(2, 1). Check: both points sit exactly one unit from BB's origin, so the frame has not stretched them.

The conversion is a turn followed by a shift:

flowchart LR
  P[point in B: 1, 0] --> R[turn by 90 degrees: 0, 1]
  R --> S[shift by origin: 3, 2]
  S --> W[point in W: 3, 2]

The math

Definition: Coordinate frame

A frame FF is a pair (o,R)(\mathbf{o}, R). The vector o\mathbf{o} is the origin of FF, given in world coordinates. The matrix RR is a rotation matrix whose columns are the unit directions of FF's axes, also in world coordinates. A frame is right-handed when its three axes follow the right-hand rule, and this lesson assumes right-handed frames throughout.

Step 2 in symbols: turning

In two dimensions, a rotation by angle θ\theta counterclockwise is

R(θ)=(cos⁡θ−sin⁡θsin⁡θcos⁡θ).R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}.

For θ=90∘\theta = 90^\circ, cos⁡θ=0\cos\theta = 0 and sin⁡θ=1\sin\theta = 1, so R=(0−110)R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}. Its first column, (0,1)(0, 1), is where the x-axis of BB points in WW, which is why step 2 gave that vector.

Step 3 in symbols: shifting

Let oB=(3,1)\mathbf{o}_B = (3, 1) be the origin of BB in WW. A point with coordinates pB\mathbf{p}_B in BB has world coordinates

pW=R pB+oB.\mathbf{p}_W = R\,\mathbf{p}_B + \mathbf{o}_B.

The rotation is applied first and the shift second. This order matters, and the common mistake section shows what goes wrong otherwise.

Step 4 in symbols: reading the example

Applying the formula to pB=(1,0)\mathbf{p}_B = (1, 0) gives

pW=(0−110)(10)+(31)=(01)+(31)=(32).\mathbf{p}_W = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} + \begin{pmatrix} 3 \\ 1 \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \end{pmatrix} + \begin{pmatrix} 3 \\ 1 \end{pmatrix} = \begin{pmatrix} 3 \\ 2 \end{pmatrix}.

Going back: from world to frame

Solve the formula for pB\mathbf{p}_B. Subtract the origin and multiply by the transpose of RR. The transpose is the inverse here because a rotation is an orthogonal matrix:

pB=RT(pW−oB).\mathbf{p}_B = R^{\mathsf{T}}\bigl(\mathbf{p}_W - \mathbf{o}_B\bigr).

Stacking frames

With homogeneous coordinates, which add a 1 to each point, the turn and the shift become one Matrix T=(Ro0T1)T = \begin{pmatrix} R & \mathbf{o} \\ \mathbf{0}^{\mathsf{T}} & 1 \end{pmatrix}, and (pW1)=T(pB1)\begin{pmatrix} \mathbf{p}_W \\ 1 \end{pmatrix} = T \begin{pmatrix} \mathbf{p}_B \\ 1 \end{pmatrix}. If frame CC is attached to frame BB with matrix TBCT_{BC}, then TWC=TWB TBCT_{WC} = T_{WB}\,T_{BC}. A chain of links is a product of matrices read right to left, which is why a robot can compute its gripper position by multiplying one matrix per joint.

Worked examples

Example
Tiny: a frame with no turn

Let frame BB have the same axes as WW, with its origin at (2,0)(2, 0). Take the point (1,1)(1, 1) in BB.

  1. Turning does nothing, so the offset stays (1,1)(1, 1).
  2. Add the origin: (1,1)+(2,0)=(3,1)(1, 1) + (2, 0) = (3, 1).
  3. The point sits at (3,1)(3, 1) in WW.
  4. Check: BB's origin is 2 units to the right, and the point is one unit further right and one unit up from there, which gives (3,1)(3, 1).
Example
Standard: the origin of W, seen from B

Use the frames from the How it works section, where oB=(3,1)\mathbf{o}_B = (3, 1) and R=(0−110)R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}. Find where the origin of WW sits in BB.

  1. The origin of WW has world coordinates pW=(0,0)\mathbf{p}_W = (0, 0).
  2. Subtract oB\mathbf{o}_B: (0,0)−(3,1)=(−3,−1)(0, 0) - (3, 1) = (-3, -1).
  3. Multiply by RT=(01−10)R^{\mathsf{T}} = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix}: the first entry is 0×(−3)+1×(−1)=−10 \times (-3) + 1 \times (-1) = -1, and the second is −1×(−3)+0×(−1)=3-1 \times (-3) + 0 \times (-1) = 3.
  4. So the origin of WW is at (−1,3)(-1, 3) in BB.
  5. Check by going back: R(−1,3)=(0×(−1)−1×3, 1×(−1)+0×3)=(−3,−1)R(-1, 3) = (0 \times (-1) - 1 \times 3,\ 1 \times (-1) + 0 \times 3) = (-3, -1), and adding oB\mathbf{o}_B gives (0,0)(0, 0), the origin of WW.
Example
Realistic: a lidar on a mobile robot

A mobile robot stands at (4,2)(4, 2) metres in a room, facing the same direction as the world y-axis, so its frame BB is turned 90 degrees counterclockwise. Its lidar sits 0.3 metres ahead of the robot's centre, so the lidar's origin in BB is (0.3,0)(0.3, 0). The lidar reports an obstacle 2.0 metres straight ahead of itself, which in the lidar frame is (2.0,0)(2.0, 0).

  1. Put the obstacle in BB by adding the lidar offset: (0.3,0)+(2.0,0)=(2.3,0)(0.3, 0) + (2.0, 0) = (2.3, 0).
  2. Turn into world directions with R=(0−110)R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}: R(2.3,0)=(0,2.3)R(2.3, 0) = (0, 2.3).
  3. Add the robot position: (0,2.3)+(4,2)=(4,4.3)(0, 2.3) + (4, 2) = (4, 4.3).
  4. The obstacle is at (4,4.3)(4, 4.3) metres in the room, 2.3 metres north of the robot.

Try it: the robot now turns to face the negative x-direction, so its rotation is 180 degrees. Where is the same obstacle in the room? Answer: R180=(−100−1)R_{180} = \begin{pmatrix} -1 & 0 \\ 0 & -1 \end{pmatrix}, so R180(2.3,0)=(−2.3,0)R_{180}(2.3, 0) = (-2.3, 0), and adding (4,2)(4, 2) gives (1.7,2)(1.7, 2).

Common mistakes and tradeoffs

It is tempting to think a frame is just a set of numbers. In fact a frame is a reference, an origin and a set of directions, and the numbers are only the address of a point in it. Confusing the two leads to code that stores coordinates without saying which frame they belong to, which is hard to debug later.

It is tempting to shift first and then rotate. In fact the rotation acts on the point's position within its own frame, before the frame is moved. Using the example from the worked section, adding (3,1)(3, 1) to (1,0)(1, 0) first gives (4,1)(4, 1), and turning that gives (−1,4)(-1, 4), which is the wrong place. Following the formula pW=R pB+oB\mathbf{p}_W = R\,\mathbf{p}_B + \mathbf{o}_B avoids this.

It is tempting to mix right-handed and left-handed conventions silently. In fact the sign of a rotation depends on the handedness, so a sensor that reports in one convention and a planner that assumes another will disagree in sign, and the error looks like a mirror image. Write the convention down in the code and check it at each boundary.

Use frames when a part of the system moves, or when a sensor is mounted at a fixed offset from the thing it measures. Do not add a frame for every object: a fixed table that never moves can be written in the room frame. The alternatives are to store one matrix per link and multiply them, which is the usual choice for a robot, or to store each pose as a position and a unit quaternion, which uses fewer numbers and avoids drift in the rotation matrix but is harder to read at a glance.

History

People located points with numbers long before robotics existed. René Descartes published the coordinate method in 1637 in La Géométrie, where a point is given by its distances along fixed lines. The idea that a robot's joints should each carry a frame came later. In 1955, Jacques Denavit and Richard Hartenberg published a convention for attaching a frame to each link of a linkage, so that the whole machine could be described by a short list of numbers per link. That convention, which is now called Denavit-Hartenberg parameters, made it practical to compute the position of an arm's tool from its joint angles, and it is still widely taught and used.

Recap

  • A coordinate frame is an origin plus a set of directions, and the same point has different coordinates in different frames.
  • Converting from a frame to the world is a turn by the frame's rotation followed by a shift by its origin, in that order.
  • Converting back uses the transpose of the rotation, since a rotation's inverse is its transpose.
  • Chains of frames multiply as matrices, which is how a robot computes the position of its tool.
  • Next, read Rigid Body Transformation for how one turn and one shift are packed into a single matrix, and Visual SLAM for how a moving sensor's frames are used to build a map.

Check yourself

QuestionA frame B has its origin at (5, 0) in the world and no rotation. A point is at (2, 3) in B. Where is it in the world?Show answer

Since there is no rotation, the offset stays (2, 3). Adding the origin gives (5,0)+(2,3)=(7,3)(5, 0) + (2, 3) = (7, 3).

QuestionA frame is rotated 90 degrees counterclockwise and has its origin at (1, 1) in the world. Using pW=R pB+oB\mathbf{p}_W = R\,\mathbf{p}_B + \mathbf{o}_B, where is the point (2, 0) in B?Show answer

The rotation maps (2,0)(2, 0) to (0,2)(0, 2). Adding the origin gives (0,2)+(1,1)=(1,3)(0, 2) + (1, 1) = (1, 3).

QuestionWhy does the order of turning and shifting matter? Give a case where doing it in the wrong order gives a different answer.Show answer

A turn is a linear map about the origin of the frame it acts in, and a shift moves that origin. Turning after shifting moves the point around the wrong center. With the frame at (3, 1) rotated 90 degrees and the point at (1, 0), turning first gives (3, 2), while shifting first then turning gives (-1, 4). The two differ, so the formula must apply the rotation first.

QuestionA lidar reports an obstacle at (1.0, 0) in its own frame. The lidar sits at (0, 0.2) in the robot frame, and the robot frame is at (2, 2) in the world with no rotation. Where is the obstacle in the world?Show answer

The obstacle in the robot frame is (0,0.2)+(1.0,0)=(1.0,0.2)(0, 0.2) + (1.0, 0) = (1.0, 0.2). With no rotation the world position is (2,2)+(1.0,0.2)=(3.0,2.2)(2, 2) + (1.0, 0.2) = (3.0, 2.2).

Sources