exupero's blog
RSSApps

Taxicab geometry

In college I made an interactive geometry sketchpad based on the Manhattan distance. I implemented it in Python but sometime later rewrote it in ClojureScript to make it easier to distribute. Since the original app was originally used as an aid for a class presentation, neither it nor its successor included much in-app explanation of why certain shapes looked so different. In this and the next few posts I'll unpack the geometry a little.

Euclidean geometry measures distance by the shortest possible line. The Manhattan distance, by contrast, measures only along perpendicular lines parallel to some set of axes, a system which evokes the perpendicular streets of cities and gives the metric the name "Manhattan distance" or, more generally, taxicab geometry. (A generalization of both Euclidean distance and Manhattan distance is the Minkowski distance.)

Since taxicab geometry changes the definition of distance, any shape whose definition depends on distance also changes. The most obvious change is a circle, a set of points equidistant from a center point. Under taxicab geometry, a circle looks like this:

CCAABB

You can confirm that points A and B are both 5 units from C when measured along gridlines, as are all the other points on the diamond. Note, too, that there are multiple paths you can follow along the grid to get from C to B, but all of them are 5 units long.

If someone asked you to draw a square circle, you may be tempted to tell them it's impossible, but that's because Euclidean geometry teaches us to assume that circles and squares are two completely different shapes. Taxicab geometry shows us they aren't. A circle is a set of points equidistant from a center point, while a square is four equal-length sides connected at right angles. Those two definitions aren't inherently incompatible. The seeming contradiction is a result of our assumption that distance is measured along a straight line. That assumption is so ingrained that it's difficult to identify, making it tough to break and draw a square circle. But difficult as it is, it's not impossible, as taxicab geometry reveals.

In three dimensions, a sphere under taxicab geometry is an octahedron. Interestingly, cross sections of it parallel to an axial plane are diamond-shaped circles, a property we might expect from the cross sections of Euclidean spheres, though it doesn't hold for cross sections parallel to non-axial planes.

In the next post we'll explore ellipses.