TactivergeLite

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?

About 35 min · 3 goals · Checked by automated tests · Full interactive version

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.

Predict

You are heading 350° and the waypoint's bearing is 10°. Which turn is best?

  1. Turn left 340°
  2. Turn right 20°
  3. Turn right 340°
  4. 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.

You can also open the interactive on the full site when you have a faster connection.

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

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

°

°

°

Practice 4. Which call gives a compass bearing (clockwise from north) for a displacement of e km east and n km north?

km

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

← Body frame, world frame: how a vehicle sees the worldRadians and the unit circle →