Peano curve
See Wikipedia. Extract below
For an explanation see the README on GitHub.
In geometry, the Peano curve is the first example of a space-filling curve to be discovered, by Giuseppe Peano in 1890. Peano's curve is a surjective, continuous function from the unit interval onto the unit square, however it is not injective. Peano was motivated by an earlier result of Georg Cantor that these two sets have the same cardinality. Because of this example, some authors use the phrase "Peano curve" to refer more generally to any space-filling curve
Construction
Peano's curve may be constructed by a sequence of steps, where the th step constructs a set of squares, and a sequence of the centers of the squares, from the set and sequence constructed in the previous step. As a base case, consists of the single unit square, and is the one-element sequence consisting of its center point. In step , each square of is partitioned into nine smaller equal squares, and its center point c is replaced by a contiguous subsequence of the centers of these nine smaller squares. This subsequence is formed by grouping the nine smaller squares into three columns, ordering the centers contiguously within each column, and then ordering the columns from one side of the square to the other, in such a way that the distance between each consecutive pair of points in the subsequence equals the side length of the small squares. There are four such orderings possible:
- Left three centers bottom to top, middle three centers top to bottom, and right three centers bottom to top
- Right three centers bottom to top, middle three centers top to bottom, and left three centers bottom to top
- Left three centers top to bottom, middle three centers bottom to top, and right three centers top to bottom
- Right three centers top to bottom, middle three centers bottom to top, and left three centers top to bottom
Among these four orderings, the one for
is chosen in such a way that the distance between the first
point of the ordering and its predecessor in
also equals the side length of the small squares. If
was the first point in its ordering, then the first of these four orderings is chosen for the nine
centers that replace .
The Peano curve itself is the limit of the curves through the sequences of square centers, as
goes to infinity.