Vectors and reference frames
Represent direction as well as magnitude and transform simple 2D observations so a robot can interpret a camera or sensor mounted at an angle.
- Resolve and rotate a 2D vector between named coordinate frames while checking direction, magnitude, and sign.
Understand
The working idea
A scalar has magnitude only: 2 metres, 5 seconds, 12 volts. A vector also has direction. “The toy car moved 2 m” is incomplete for mapping; “2 m east” can be represented by components such as [2, 0] in a frame whose x-axis points east and y-axis north. Components are not intrinsic labels on the motion. They depend on the chosen coordinate frame.
In two dimensions, a vector of magnitude r at angle θ from +x has components x = r cos θ and y = r sin θ. Its magnitude is sqrt(x² + y²). To express a vector from a sensor frame in a body frame rotated by θ, use the rotation matrix R(θ) = [[cos θ, -sin θ], [sin θ, cos θ]]. Multiplying R by the component column rotates the description. Translation is separate: a direction vector is rotated but not shifted, while a point measured from a camera may need both rotation and the camera's position offset.
This distinction drives mounting decisions. A camera facing 90° left of a robot cannot feed its “forward” coordinate directly into robot forward motion. If the camera reports an object 0.40 m along its own forward axis, the body-frame vector is approximately [0, 0.40] m under the stated axis convention. Explicit frame names—camera, body, world—prevent silent sign errors.
A common misconception is that the same pair of numbers describes a vector in every frame. Another is adding a position offset to a velocity or force vector merely because both are drawn as arrows. Name each frame, draw positive axes, state whether the quantity is a point or free vector, and check that rotation preserves magnitude. If the length changes during a pure rotation, the calculation is wrong.
Follow the reasoning
Worked example
A range sensor points 30° left of a toy car's forward +x axis and reports an obstacle 0.80 m straight ahead in its sensor frame. Find the body-frame components, ignoring sensor position offset.
- 1
Represent the sensor reading as [0.80, 0] m in the sensor frame.
- 2
Rotate by +30°: x = 0.80 cos 30° = 0.693 m.
- 3
Compute y = 0.80 sin 30° = 0.400 m, where +y was defined as left.
The obstacle vector is approximately [0.693, 0.400] m in the car body frame.
Sanity checksqrt(0.693² + 0.400²) ≈ 0.800 m, so the pure rotation preserved distance; both components are positive for forward-left.
Try it yourself
Independent check
Move to the bench
Map a sensor-relative direction into a toy-car body frame.
- toy car or paper car outline
- phone camera used only to document
- protractor
- ruler
- masking tape
- small block
Experiment
- Tape body +x and +y axes on a table and mount or draw a sensor direction 45° left of body +x.
- Place the block 300 mm along the sensor axis and predict its body x/y coordinates.
- Measure the actual table coordinates from the body origin and record deviations separately for x and y.
- Deliberately flip the sign of the sine term; plot that faulty prediction and diagnose it from the mirrored side of the car.
- Move the sensor origin 50 mm forward and decide which coordinate receives the translation offset.
Observe
- Expected before translation: x and y are each about 212 mm; actual values reflect drawing and placement tolerances.
- Expected fault clue: a sine-sign error preserves distance but places the block on the wrong side, unlike a scale error.
Sketch frames for a printer head, its carriage, and the page; state which transform would locate a nozzle point on the page.
- Keep the tabletop area clear so the taped axes do not create a trip or snag hazard.
- Do not use a moving powered car during this geometry exercise.
Keep evidence
Bench note
Record what you expected, what you actually measured or observed, and one difference worth investigating. This is self-reported evidence, not a certification.