← Writing

Which Way Are You Facing?

How to count the turns of a closed loop by glancing at a handful of points

Walk all the way around a closed loop and you arrive back facing exactly the way you started — having turned some whole number of times along the way. That number is a genuine property of the loop: stretch it, dent it, wobble it, and the number refuses to budge. Finding it looks like it should require watching yourself continuously, all the way round. It doesn’t. Pick any direction at all, mark the few points where you happen to be travelling crosswise to it, note at each whether you are curving left or right, and do one subtraction. That is the whole method.

1. A walk around a loop

Draw a closed curve on paper — any closed curve, so long as it never stops and never has a sharp corner — and imagine walking along it. At every instant you are facing some direction. Set off, keep going, and eventually you arrive back where you started, facing the way you set out.

Your heading, meanwhile, has been busy. It swung left through the bulges, swung back right through the dents, and by the time you were home it had come back to where it began. But “back where it began” is not the same as “never moved”: a direction that goes all the way around and returns has made some whole number of complete turns. One, perhaps. Or none. Or two. That count is called the turning number of the curve, and it is the subject of this article.

A closed curve with the walker's heading drawn as arrows at points around it, shaded light to dark
(a) the walk
The same heading arrows redrawn from a single origin, sweeping once around a circle
(b) the same headings, on one compass
Figure 1. Left: a closed curve with the walker’s heading sampled at even intervals, shaded from light (the start) to dark (the finish). Right: the very same arrows, all moved to a common origin. Nothing has been changed except where the arrows are drawn — and now you can see them sweep once around the compass, light to dark, and close up. This loop has turning number one.

The right-hand panel is the whole idea in one picture. Strip away where you were and keep only which way you were facing, and the walk becomes a spin. Counting turns of the curve means counting laps of that spin.

2. The heading remembers everything

It is worth watching the heading more carefully, because it does not simply rotate steadily. Figure 2 plots it against how far you have walked: not as a compass point, which would wrap around and lose count, but as a running total, the way a car’s odometer keeps climbing rather than resetting.

A graph of accumulated heading against distance walked, rising with three dips and ending exactly one full turn higher
Figure 2. The running total of the heading as you walk the curve of Figure 1. It climbs where the curve bulges outward and slides back where the curve dents inward — three times each — and finishes exactly one full turn above where it started. The dips are real, and they are the reason the count is interesting: the heading does not march steadily round, it wanders, and still lands on a whole number.

Three things are worth noticing. The graph wanders — that is the curve’s dents talking. It ends at exactly one full turn, not 0.98 of one, because the curve closes up and the heading has to come home. And nothing about the wandering in the middle affected the final answer. You could push the curve around, deepen the dents, add new ones, and as long as you never tear the curve or put a corner in it, the graph would still finish on the same horizontal line.

3. Not every loop turns once

A circle turns once. So does the wobbly loop above, dents and all. But the count is not always one.

An oval with tangent arrows, labelled one
(a) a plain oval
A figure-eight with tangent arrows, labelled zero
(b) a figure-eight
A curve that loops around twice, labelled two
(c) a double loop
Figure 3. Three loops and their turning numbers. The figure-eight turns one way around the top lobe and the other way around the bottom one; the two cancel exactly, and it scores zero. The double loop winds around twice before closing, and scores two.

The figure-eight is the instructive one. It is not that it never turns — it turns constantly. It is that the turning cancels: a full turn one way around the upper lobe, a full turn the other way around the lower one. Net zero. And no amount of stretching will ever make a figure-eight into an oval, because you cannot get from zero to one without, at some moment, putting a corner in the curve or pulling it apart.

4. You don’t have to watch the whole walk

So far, finding the number has meant tracking your heading continuously, all the way around. That is a lot of watching for a single integer. Here is the shortcut.

Pick a direction — any direction. North, say. Now walk the loop again, but instead of watching constantly, only stop at the moments when you are travelling exactly crosswise to north: due east or due west, neither gaining nor losing ground northward. On a generic loop there are only finitely many such moments, and they are easy to spot — they are the points where the curve is momentarily level, the tops of its humps and the bottoms of its troughs with respect to your chosen direction.

At each of those points, ask one question: am I curving left or curving right? Mark it + for left, for right. Then:

\[ \text{turning number} \;=\; \frac{(\text{number of } +) - (\text{number of } -)}{2} . \]

That is the entire recipe. Count, subtract, halve.

The wobbly closed curve with six marked points, four blue plus and two orange minus, tallying to one
Figure 4. The curve of Figure 1 with north as the chosen direction. Dotted lines mark the six heights at which the curve runs level. At four of them the curve is bending left (+), at two it is bending right (). Four minus two is two; halved, that is one — which is what the continuous walk of Figure 2 took a whole lap to establish.

5. Why halve?

The division by two looks arbitrary until you notice how the marks are arranged. Follow the curve from one mark to the next and watch what your heading does between them.

Between the marks you are never crosswise to north, which means you are steadily gaining northward ground or steadily losing it — you are climbing, or you are descending, with no dithering in between. So the marks alternate: peak, trough, peak, trough, all the way around. And a stretch that runs from a peak to a trough swings your heading through half a turn, no more and no less, because you start facing one way across north and end facing the other.

So every mark sits between two stretches, and contributes half a turn’s worth of evidence to each of them. Add up what all the marks say and you have counted every stretch exactly twice. Hence the halving. The signs are there to record which way each half-turn went: a left-hand bend adds, a right-hand bend subtracts, and the dents of Figure 2 — those downward slides — are precisely the stretches bracketed by minus marks.

6. The direction was never the point

North was an arbitrary choice, and a suspicious one: the marks are entirely at its mercy. Tilt your chosen direction and the marks slide along the curve, appear in pairs, vanish in pairs. The count changes. The answer does not.

The curve marked with respect to north: six marks, four plus and two minus, tally one
(a) north — six marks
The same curve marked with respect to east: four marks, three plus and one minus, tally one
(b) east — four marks
Figure 5. The same curve, measured against two different directions. North finds six level points and tallies four plus against two minus; east finds only four and tallies three against one. Six marks or four, the arithmetic lands on one both times.

This is the part worth keeping. The chosen direction is scaffolding — it produces the marks, the marks produce the count, and then the direction drops out of the answer entirely. You are free to pick whichever direction makes the marks easiest to find, confident that the loop does not care which one you picked.

7. Count one yourself

Everything above is a few lines of Python. Sample the curve, find the points where it runs level with respect to your chosen direction, and add up the signs:

import numpy as np

# a wobbly closed loop: a circle with three dents
curve = lambda t: ((1 + 0.4*np.cos(3*t)) * np.cos(t),
                   (1 + 0.4*np.cos(3*t)) * np.sin(t))

marks, points, signs = critical_points(curve, direction=(0, 1))
print(signs)              # [ 1.  1. -1.  1. -1.  1.]
print(signs.sum() / 2)    # 1.0  -- the turning number

Change the direction and the list of signs changes; the last line does not. Change the curve to a figure-eight and it prints zero. Every figure in this article was drawn by that same code, which also checks its own arithmetic: for each curve it compares the tally against the turning number measured the slow way, by following the heading all the way around. They have always agreed, which is a reassuring thing for a shortcut to do.


Further reading


I work as an independent consultant helping engineering and computational teams solve difficult problems in geometric modeling, surface processing, and algorithmic design. If your team is tackling a non-trivial spatial or mathematical challenge, reach out directly at cvalero@carlosvalero.com.