The robot's distance sensor says, "Obstacle 1 meter ahead." Where is that on the map? It depends on where the robot is and which way it faces.
Key idea
A frame is a point of view: an origin and axes. A point $(x_r, y_r)$ in the robot's frame, for a robot at $(x, y)$ facing angle $\theta$, is on the map at
$x_m = x + x_r\cos\theta - y_r\sin\theta$, $\ y_m = y + x_r\sin\theta + y_r\cos\theta$. Rotate, then shift.
$x_m = x + x_r\cos\theta - y_r\sin\theta$, $\ y_m = y + x_r\sin\theta + y_r\cos\theta$. Rotate, then shift.
Why it works
The rotation is a matrix multiplication, the same one taught on the Math Ladder. Robots chain many of these: camera to body, body to map. Every one is rotate, then shift.
Worked example: Straight ahead
Robot at (2, 1) facing 90Β° (straight up the map). Its sensor sees a point 1 m ahead: $(1, 0)$ in its frame.
- $\cos 90^\circ = 0$, $\sin 90^\circ = 1$.
- $x_m = 2 + 1 \cdot 0 - 0 = 2$, $y_m = 1 + 1 \cdot 1 + 0 = 2$.
Answer: (2, 2).
Common mistake
Adding the robot's position but forgetting to rotate by its heading. That is only right when the robot faces along the map's $x$-axis.