Chapter 9: Coordinate Frames and Spatial Representation (Intro Only)
Lesson 1: Why Frames Matter in Robotics
Robots live in 3D space, but every measurement and command must be expressed in some coordinate frame. This lesson explains what a frame is, why multiple frames are unavoidable, and how a single geometric object can have many different coordinate descriptions. We build the mathematical foundations for consistent spatial reasoning used throughout robotics.
1. Conceptual Overview: The Frame Problem
A robot does not perceive or act in “pure geometry.” It sees numbers reported by sensors and sends numbers to actuators. Those numbers are meaningless unless we specify with respect to what they were computed. That reference is a coordinate frame.
Examples:
- A camera gives a 3D point in the camera’s frame.
- A mobile robot’s odometry gives pose in its body frame.
- A task (“move the tool to (0.5, 0.2, 0.3)”) must state the frame: world? base? tool?
flowchart TD
G["Geometric Quantity (point, vector, pose)"] --> C["Choose a frame"]
C --> R["Represent quantity as coordinates"]
R --> U["Use in control / planning / perception"]
U --> E["Execute in physical space"]
E --> V["New sensor readings"]
V --> G
The key message: geometry is frame-invariant, coordinates are not. A point in space is a physical object; its numerical coordinates depend on which axes you choose.
2. Mathematical Definition of a Coordinate Frame
In Euclidean 3D space, a coordinate frame \( \mathcal{F} \) is an ordered orthonormal basis:
\[ \mathcal{F} = \{ \mathbf{e}_1, \mathbf{e}_2, \mathbf{e}_3 \}, \quad \mathbf{e}_i \in \mathbb{R}^3,\; \mathbf{e}_i^\top \mathbf{e}_j = \delta_{ij}. \]
Any vector \( \mathbf{v} \in \mathbb{R}^3 \) can be written uniquely in that basis:
\[ \mathbf{v} = v_1\,\mathbf{e}_1 + v_2\,\mathbf{e}_2 + v_3\,\mathbf{e}_3. \]
The numbers \( (v_1, v_2, v_3) \) are the coordinates of \( \mathbf{v} \) in frame \( \mathcal{F} \). We denote this coordinate column as \( [\mathbf{v}]_{\mathcal{F}} \in \mathbb{R}^3 \).
If \( \mathbf{E}_{\mathcal{F}} = [\mathbf{e}_1\;\mathbf{e}_2\;\mathbf{e}_3] \) is the basis matrix, then:
\[ \mathbf{v} = \mathbf{E}_{\mathcal{F}}\, [\mathbf{v}]_{\mathcal{F}} \quad \text{and} \quad [\mathbf{v}]_{\mathcal{F}} = \mathbf{E}_{\mathcal{F}}^\top \mathbf{v}. \]
Interpretation: \( \mathbf{v} \) is the physical vector. \( [\mathbf{v}]_{\mathcal{F}} \) is the coordinate encoding the robot stores or computes with.
3. The Same Vector in Two Frames (Change of Basis)
Consider two frames \( \mathcal{A} \) and \( \mathcal{B} \) with basis matrices \( \mathbf{E}_{\mathcal{A}} \) and \( \mathbf{E}_{\mathcal{B}} \). The same geometric vector \( \mathbf{v} \) satisfies:
\[ \mathbf{v} = \mathbf{E}_{\mathcal{A}}[\mathbf{v}]_{\mathcal{A}} = \mathbf{E}_{\mathcal{B}}[\mathbf{v}]_{\mathcal{B}}. \]
Multiply by \( \mathbf{E}_{\mathcal{B}}^\top \):
\[ [\mathbf{v}]_{\mathcal{B}} = \mathbf{E}_{\mathcal{B}}^\top \mathbf{E}_{\mathcal{A}} \,[\mathbf{v}]_{\mathcal{A}} \equiv \mathbf{R}_{\mathcal{B}\mathcal{A}} \,[\mathbf{v}]_{\mathcal{A}}. \]
Here \( \mathbf{R}_{\mathcal{B}\mathcal{A}} \) is a change-of-coordinates matrix. In robotics, when frames are rigidly related, this matrix is a rotation matrix (more in Lesson 3).
Proposition (Orthonormal-change invariance): If both bases are orthonormal, then \( \mathbf{R}_{\mathcal{B}\mathcal{A}} \) is orthonormal and preserves vector lengths.
Proof:
Since \( \mathbf{E}_{\mathcal{A}}^\top \mathbf{E}_{\mathcal{A}} = \mathbf{I} \) and \( \mathbf{E}_{\mathcal{B}}^\top \mathbf{E}_{\mathcal{B}} = \mathbf{I} \), we compute:
\[ \begin{aligned} \mathbf{R}_{\mathcal{B}\mathcal{A}}^\top \mathbf{R}_{\mathcal{B}\mathcal{A}} &= (\mathbf{E}_{\mathcal{A}}^\top \mathbf{E}_{\mathcal{B}}) (\mathbf{E}_{\mathcal{B}}^\top \mathbf{E}_{\mathcal{A}}) \\ &= \mathbf{E}_{\mathcal{A}}^\top (\mathbf{E}_{\mathcal{B}} \mathbf{E}_{\mathcal{B}}^\top) \mathbf{E}_{\mathcal{A}} = \mathbf{E}_{\mathcal{A}}^\top \mathbf{I}\,\mathbf{E}_{\mathcal{A}} = \mathbf{I}. \end{aligned} \]
Therefore \( \mathbf{R}_{\mathcal{B}\mathcal{A}} \) is orthonormal. For any coordinates \( \mathbf{x} = [\mathbf{v}]_{\mathcal{A}} \):
\[ \|[\mathbf{v}]_{\mathcal{B}}\|^2 = \mathbf{x}^\top \mathbf{R}_{\mathcal{B}\mathcal{A}}^\top \mathbf{R}_{\mathcal{B}\mathcal{A}} \mathbf{x} = \mathbf{x}^\top \mathbf{I} \mathbf{x} = \|[\mathbf{v}]_{\mathcal{A}}\|^2. \]
So distances and angles are physical invariants even though coordinates change. □
4. Why Multiple Frames Are Unavoidable in Robotics
A robot system is a network of components with natural local frames:
- World frame: global reference for the environment.
- Body/base frame: attached to robot chassis/base.
- Sensor frames: defined by each camera, IMU, LiDAR, etc.
- Tool/end-effector frame: attached to the working tip.
If a sensor measures a quantity in its own frame, controllers must transform it to the body or world frame to compare against desired trajectories. Even simple control laws in linear control (e.g., \( \mathbf{u} = -\mathbf{K}\mathbf{x} \)) require a consistent definition of state coordinates \( \mathbf{x} \).
flowchart TD
W["World frame"] --> B["Robot body frame"]
B --> S1["Sensor frame"]
B --> T["Tool frame"]
S1 --> D["Sensor data in sensor coords"]
D --> X["Transform to body/world coords"]
X --> C["Control / planning"]
C --> T
5. A Simple Numeric Example (2D for Intuition)
Let frame \( \mathcal{A} \) be standard axes, and frame \( \mathcal{B} \) be rotated by 90 degrees counterclockwise. Then:
\[ \mathbf{R}_{\mathcal{B}\mathcal{A}} = \begin{bmatrix} 0 & 1\\ -1 & 0 \end{bmatrix}. \]
A vector with coordinates \( [\mathbf{v}]_{\mathcal{A}} = \begin{bmatrix}2\\1\end{bmatrix} \) is seen in frame \( \mathcal{B} \) as:
\[ [\mathbf{v}]_{\mathcal{B}} = \mathbf{R}_{\mathcal{B}\mathcal{A}}[\mathbf{v}]_{\mathcal{A}} = \begin{bmatrix} 0 & 1\\ -1 & 0 \end{bmatrix} \begin{bmatrix} 2\\1 \end{bmatrix} = \begin{bmatrix} 1\\-2 \end{bmatrix}. \]
The geometry is unchanged. Only the coordinate description differs.
6. Coding Lab: Coordinate Change in Practice
We implement a basic coordinate transformation between two orthonormal frames. These snippets are deliberately minimal and will be reused later when we discuss rotations, translations, and frame trees.
6.1 Python (NumPy)
import numpy as np
# R_BA: coordinates in A -> coordinates in B
R_BA = np.array([[0, 1],
[-1, 0]]) # 90 deg CCW rotation
v_A = np.array([2.0, 1.0])
v_B = R_BA @ v_A
print("v_A =", v_A)
print("v_B =", v_B)
print("lengths:", np.linalg.norm(v_A), np.linalg.norm(v_B))
6.2 C++ (Eigen)
#include <iostream>
#include <Eigen/Dense>
int main() {
Eigen::Matrix2d R_BA;
R_BA << 0, 1,
-1, 0;
Eigen::Vector2d v_A(2.0, 1.0);
Eigen::Vector2d v_B = R_BA * v_A;
std::cout << "v_A = " << v_A.transpose() << std::endl;
std::cout << "v_B = " << v_B.transpose() << std::endl;
std::cout << "lengths: " << v_A.norm() << " " << v_B.norm() << std::endl;
return 0;
}
6.3 Java (EJML)
import org.ejml.simple.SimpleMatrix;
public class FrameChange2D {
public static void main(String[] args) {
SimpleMatrix R_BA = new SimpleMatrix(new double[][] {
{0, 1},
{-1, 0}
});
SimpleMatrix v_A = new SimpleMatrix(2, 1, true, new double[] {2.0, 1.0});
SimpleMatrix v_B = R_BA.mult(v_A);
System.out.println("v_A = \n" + v_A);
System.out.println("v_B = \n" + v_B);
System.out.println("lengths: " +
v_A.normF() + " " + v_B.normF());
}
}
6.4 MATLAB / Simulink
% Coordinate change in MATLAB
R_BA = [0 1; -1 0]; % 90 deg CCW rotation
v_A = [2; 1];
v_B = R_BA * v_A;
disp("v_A ="); disp(v_A);
disp("v_B ="); disp(v_B);
disp("lengths ="); disp([norm(v_A), norm(v_B)]);
% Simulink idea:
% Use a Constant block for v_A and R_BA,
% then a Matrix Multiply block to produce v_B.
Across languages, the key operation is the same: \( [\mathbf{v}]_{\mathcal{B}} = \mathbf{R}_{\mathcal{B}\mathcal{A}}[\mathbf{v}]_{\mathcal{A}} \).
7. Problems and Solutions
Problem 1 (Coordinates vs. Geometry): Let frames \( \mathcal{A} \) and \( \mathcal{B} \) be orthonormal with change matrix \( \mathbf{R}_{\mathcal{B}\mathcal{A}} \). Show that if \( [\mathbf{v}]_{\mathcal{B}} = \mathbf{0} \) then \( [\mathbf{v}]_{\mathcal{A}} = \mathbf{0} \).
Solution:
Since \( [\mathbf{v}]_{\mathcal{B}} = \mathbf{R}_{\mathcal{B}\mathcal{A}}[\mathbf{v}]_{\mathcal{A}} \), we have:
\[ \mathbf{0} = \mathbf{R}_{\mathcal{B}\mathcal{A}}[\mathbf{v}]_{\mathcal{A}}. \]
The matrix \( \mathbf{R}_{\mathcal{B}\mathcal{A}} \) is orthonormal, hence invertible with \( \mathbf{R}_{\mathcal{B}\mathcal{A}}^{-1} = \mathbf{R}_{\mathcal{B}\mathcal{A}}^\top \). Multiply both sides by the inverse:
\[ [\mathbf{v}]_{\mathcal{A}} = \mathbf{R}_{\mathcal{B}\mathcal{A}}^{-1}\mathbf{0} = \mathbf{0}. \]
So zero coordinates in one orthonormal frame imply the physical vector is zero, hence coordinates are zero in all frames. □
Problem 2 (Length Preservation): Let \( \mathbf{R} \in \mathbb{R}^{3\times 3} \) be orthonormal: \( \mathbf{R}^\top \mathbf{R} = \mathbf{I} \). Prove that \( \|\mathbf{R}\mathbf{x}\| = \|\mathbf{x}\| \) for all \( \mathbf{x} \in \mathbb{R}^3 \).
Solution:
\[ \begin{aligned} \|\mathbf{R}\mathbf{x}\|^2 &= (\mathbf{R}\mathbf{x})^\top(\mathbf{R}\mathbf{x}) = \mathbf{x}^\top \mathbf{R}^\top \mathbf{R}\mathbf{x} = \mathbf{x}^\top \mathbf{I}\mathbf{x} = \|\mathbf{x}\|^2. \end{aligned} \]
Since norms are nonnegative, taking square roots gives \( \|\mathbf{R}\mathbf{x}\| = \|\mathbf{x}\| \). □
Problem 3 (Robot Interpretation): A range sensor mounted on a robot reports a detected wall-normal vector as \( [\mathbf{n}]_{\mathcal{S}} = (0,1,0)^\top \) in the sensor frame. If the sensor frame is rotated relative to the body frame by \( \mathbf{R}_{\mathcal{B}\mathcal{S}} \), write the body-frame normal vector in terms of these quantities.
Solution:
Coordinates transform by left-multiplication with the change matrix:
\[ [\mathbf{n}]_{\mathcal{B}} = \mathbf{R}_{\mathcal{B}\mathcal{S}}[\mathbf{n}]_{\mathcal{S}}. \]
This is the quantity a body-frame controller would use.
Problem 4 (2D Computation): With \( \mathbf{R}_{\mathcal{B}\mathcal{A}} = \begin{bmatrix} \cos\theta & \sin\theta\\ -\sin\theta & \cos\theta \end{bmatrix} \), compute \( [\mathbf{v}]_{\mathcal{B}} \) for \( [\mathbf{v}]_{\mathcal{A}} = (1,0)^\top \).
Solution:
\[ [\mathbf{v}]_{\mathcal{B}} = \mathbf{R}_{\mathcal{B}\mathcal{A}} \begin{bmatrix}1\\0\end{bmatrix} = \begin{bmatrix}\cos\theta\\ -\sin\theta\end{bmatrix}. \]
The unit x-axis of frame \( \mathcal{A} \) is seen in \( \mathcal{B} \) as a direction rotated by \( \theta \).
8. Summary
We defined coordinate frames as orthonormal bases, distinguished physical vectors from their coordinate representations, and derived the change-of-basis relation \( [\mathbf{v}]_{\mathcal{B}} = \mathbf{R}_{\mathcal{B}\mathcal{A}}[\mathbf{v}]_{\mathcal{A}} \). The invariance of geometry under orthonormal frame changes explains why robotics must carefully manage frames to avoid inconsistent reasoning. Next, we will name and organize common robotic frames (Lesson 2).
9. References (Theoretical Papers)
- Chasles, M. (1830). Note sur les propriétés générales du système de deux corps semblables. Bulletin des Sciences Mathématiques, 14, 321–326.
- Euler, L. (1776). Formulae generales pro translatione quacunque corporum rigidorum. Novi Commentarii Academiae Scientiarum Petropolitanae, 20, 189–207.
- Schönemann, P.H. (1966). A generalized solution of the orthogonal Procrustes problem. Psychometrika, 31(1), 1–10.
- Horn, B.K.P. (1987). Closed-form solution of absolute orientation using unit quaternions. Journal of the Optical Society of America A, 4(4), 629–642.
- Park, F.C. (1995). Distance metrics on the rigid-body motions with applications to mechanism design. Journal of Mechanical Design, 117(1), 48–54.