# Module 1.2: Coordinate Frames

- Course: [Course 1: Frames, Transform Networks & Intro to Kinematics](https://roboticsconcepts.dev/courses/frames-transform-networks-kinematics.md)
- HTML Page: https://roboticsconcepts.dev/courses/frames-transform-networks-kinematics/coordinate-frames/
- Key Concepts: Local vs. global coordinate frames, 2D translation & heading, Visual 2×2 rotation matrices

If you tell a friend sitting across a table to 'move the coffee mug two inches to the left,' you immediately hit a classic robotics bug: your left isn't their left. Robots have the exact same problem across every camera, wheel, and gripper mounted on their body.

## Why one global grid is never enough

A room has a convenient origin — maybe one corner of the lab floor. That's great for placing tables and charging docks, but terrible for a wrist camera trying to line up with a bolt. The camera only knows what's in front of its own lens: 'the bolt is 12 cm straight ahead and 3 cm to my right.'

So instead of forcing every sensor to do mental gymnastics against the corner of the room, we attach a local coordinate frame — an origin point plus a pair of perpendicular axes (Red for X, Green for Y) — directly to each part that cares about its own point of view.

## Reading a 2×2 rotation matrix without memorizing formulas

Rotation matrices look intimidating when they're introduced as tables of sines and cosines. There's a much simpler way to read one: its columns are literally just the coordinates of the robot's local X and Y axes drawn inside the room.

If the robot turns by angle θ, its forward X axis points to (cos θ, sin θ), and its sideways Y axis (90° counterclockwise) points to (-sin θ, cos θ). Stack those two arrows side-by-side and you've built the 2×2 rotation matrix from scratch.

## Interactive Sandbox: Coordinate Frames & Visual 2×2 Rotation Lab

Drag the orange target cone around the room below, then toggle between Room Frame and Robot Local Frame while turning the robot's heading slider. Keep an eye on the two color-coded columns of the 2×2 matrix.

## Two ways to read the same geometry

Notice what happens when you switch to Robot Local Frame: the robot stops moving on your screen, and the entire room rotates around it instead. Nothing changed physically — the distance and angle between the robot and the cone are identical — we just changed whose eyes we're looking through.

To convert a point from the room into the robot's local frame, we first subtract the robot's position (shifting the origin onto the robot) and then project onto the robot's X and Y axis vectors using the transpose of that rotation matrix.

## 2×2 rotation matrix as axis columns

```text
R(θ) = [ cos θ   -sin θ ;  sin θ   cos θ ]   and   p_robot = R(θ)ᵀ · (p_world - t_robot)
```

Column 1 is where local X points in the world; Column 2 is where local Y points. Multiplying by Rᵀ projects any world offset onto those two local axes.

## Check Your Intuition

**Question:** A mobile robot is parked at the world origin (0, 0) facing straight along the world +Y axis (heading θ = 90°). What is the first column of its 2×2 rotation matrix?

- [ ] [ 1, 0 ]ᵀ — local X still points along world X
- [✓] [ 0, 1 ]ᵀ — local X now points along world +Y
- [ ] [ -1, 0 ]ᵀ — local X points backward

**Explanation:** The first column always tells you where the robot's forward X axis points in world coordinates. Turned 90° toward +Y, that direction is (0, 1).

## Where You'll See This in Modern Robotics

Wrist-camera policies in robot learning almost always predict motions in the camera or gripper's local frame rather than room coordinates, because 'move 2 cm closer to the mug' means the same thing no matter where the table sits in the room.

## Companion Python Notebook: 02 · Coordinate Frames & 2×2 Rotation Matrix Lab

Write world_to_robot() and robot_to_world() transforms in NumPy and plot side-by-side Room Frame vs. Robot Local Frame views.

- Open in molab (WASM): https://molab.marimo.io/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/course-1/02_coordinate_frames_rotations.py/wasm
- Open in Google Colab: https://colab.research.google.com/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/colab/course-1/02_coordinate_frames_rotations.ipynb
- Download .py: https://roboticsconcepts.dev/downloads/notebooks/course-1/02_coordinate_frames_rotations.py
- Download .ipynb: https://roboticsconcepts.dev/downloads/notebooks/colab/course-1/02_coordinate_frames_rotations.ipynb
- Run locally: `uvx marimo edit --sandbox notebooks/course-1/02_coordinate_frames_rotations.py`
