Lite / Intelligent Robotic Systems / Week 11
Heading for a waypoint: bearings and turns
A rover 200 million km from Earth must drive to a rock nobody can steer it towards in real time. What numbers does it need?
Why should I care?
Waypoint navigation is the backbone of autopilots, drones, ships and planetary rovers: a list of points on a map, and a loop that keeps turning towards the next one. The maths is a vector subtraction, an atan2 and one careful subtraction of angles. Getting the wrap-around at 360° right is what separates a smooth turn from a full pirouette.
- Compute the compass bearing and distance from a position to a waypoint.
- Find the relative bearing (how far to turn left or right) from the current heading.
- Plan a short route as a list of waypoints with bearings and leg lengths.
Predict
You are heading 350° and the waypoint's bearing is 10°. Which turn is best?
- Turn left 340°
- Turn right 20°
- Turn right 340°
- Turn left 20°
Guess first, then reveal
Turn right 20°. Naively 10 − 350 = −340, but angles wrap around: −340° is the same as +20°. Always fold the difference into the range −180° to 180° and take the short way round.
Discover
Put the aircraft at (−4, −4) km. For each of ALPHA, BRAVO and CHARLIE: predict the bearing with atan2(east, north), press 'Turn towards the target' to check, then use 'Move 2 km forward' until you arrive. How did the relative bearing change as you flew?
What the interactive shows (text version)
The diagram lists the waypoint's distance and compass bearing and the relative bearing ('turn right 35°'). Pressing 'Turn towards the target' sets the heading to the bearing (rounded to 5°); 'Move 2 km forward' steps the vehicle along its nose. Repeating the step brings the distance down to a few hundred metres.
Understand
Bearing: atan2 with the arguments swapped
The displacement to the waypoint is d = (east, north) = (wx − x, wy − y). Its distance is |d|. Its compass bearing is measured from north towards east, so it is atan2(east, north), the maths angle formula with the two arguments swapped. Add 360° to negative results to get 0–360°.
Relative bearing: how far to turn
The relative bearing is bearing − heading, folded into (−180°, 180°]. Positive means turn right (clockwise), negative means turn left. Folding matters: from heading 350° to bearing 10° the raw difference is −340°, which folds to +20°. Forgetting this sends vehicles spinning the long way round.
Routes are lists of legs
A route is a list of waypoints. Each leg has a bearing and a length, found from the displacement between consecutive points. A simple guidance loop: compute the relative bearing to the current waypoint, turn to reduce it, move, and switch to the next waypoint once within some arrival radius. Real autopilots add wind, speed limits and smoother turns, but the skeleton is this.
Explain it another way
Intuitive
Bearings are 'which way on the map'; relative bearings are 'which way from my nose'. You need both: the map tells you where to go, your nose tells you how to turn.
Technical
bearing = atan2(Δe, Δn) mod 360°; relative = ((bearing − heading + 180°) mod 360°) − 180°. Arrival is declared when |d| < r_arrive. The heading command can be a proportional controller on the relative bearing.
Mathematical
From (3, −6) km to (2, −13) km: Δ = (−1, −7). Distance = √50 ≈ 7.07 km. Bearing = atan2(−1, −7) ≈ −171.9° → 188.1°. If the heading is 170°, relative = +18.1°: turn right 18°.
Applied
Mars rovers receive routes as waypoints planned on Earth, then drive each leg themselves, using their own cameras to check progress, because a radio round trip can take tens of minutes.
Worked example 1
A rover at (0, 0) km must visit A = (3, 4) then B = (3, −2). Give each leg's bearing and length.
Leg 1: Δ = (3, 4), length 5 km, bearing atan2(3, 4) ≈ 36.9°. Leg 2: Δ = (0, −6), length 6 km, bearing atan2(0, −6) = 180° (due south).
Common mix-ups
Relative bearing is just bearing minus heading.
✓ It must be folded into −180°…180°, or the vehicle may turn the long way round.Compass bearings and maths angles use the same atan2 call.
✓ Bearings use atan2(east, north); maths angles use atan2(y, x). The order swaps.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Plan a three-waypoint route for a simulated rover from (0, 0) that visits all three diagram waypoints (ALPHA (6, 8), BRAVO (−7, 4), CHARLIE (3, −8)) in the shortest order you can find. Give each leg's bearing and length, and the total distance. Then explore the Planetary Rover Build's navigation level.
Reflect
A drone keeps overshooting waypoints and circling back. Using the idea of an arrival radius, explain one likely cause and one fix.
Write your answer on paper or in your own notes. Lite never stores what you write.
Go further
- Bearing (navigation) (Wikipedia)
Absolute and relative bearings as navigators use them.