Skip to content
Tactiverge

School/○ Innovator/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

1.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.

2.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?

Loading the interactive…

Can't use the interactive? Read a description instead

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.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

A waypoint is 5 km east and 5 km north of you. What is its compass bearing, in degrees?

°

4.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.

Open BUILD 006: Engineer a Planetary Rover →

5.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

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.

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.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2 · a fresh version every time

A rover is 4 km west and 4 km north of its lander. Its next waypoint is 9 km west and 2 km south of the lander. What compass bearing should it head on (degrees clockwise from north, 0 to 360)?

°

Practice 3

Heading 300°, waypoint bearing 40°. What is the relative bearing, in degrees from −180 to 180 (positive = turn right)?

°

Practice 4

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

Practice 5

Leg from (−2, 1) km to (4, 9) km. How long is it, in km?

km

7.Predict

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

Guess first. Being wrong here is how the surprise works.

8.Reflect

9.Go further

Concepts: Navigation frames, heading and waypoints