Gosper curve
![](http://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Gosper_curve_3.svg/220px-Gosper_curve_3.svg.png)
![](http://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Gosper_curve_1.svg/220px-Gosper_curve_1.svg.png)
The Gosper curve, named after Bill Gosper, also known as the Peano-Gosper Curve[1] and the flowsnake (a spoonerism of snowflake), is a space-filling curve whose limit set is rep-7. It is a fractal curve similar in its construction to the dragon curve and the Hilbert curve.
The Gosper curve can also be used for efficient hierarchical hexagonal clustering and indexing.[2]
Algorithm
Lindenmayer system
The Gosper curve can be represented using an L-system with rules as follows:
- Angle: 60°
- Axiom:
- Replacement rules:
In this case both A and B mean to move forward, + means to turn left 60 degrees and - means to turn right 60 degrees - using a "turtle"-style program such as Logo.
Logo
A Logo program to draw the Gosper curve using turtle graphics:
to rg :st :ln
make "st :st - 1
make "ln :ln / sqrt 7
if :st > 0 [rg :st :ln rt 60 gl :st :ln rt 120 gl :st :ln lt 60 rg :st :ln lt 120 rg :st :ln rg :st :ln lt 60 gl :st :ln rt 60]
if :st = 0 [fd :ln rt 60 fd :ln rt 120 fd :ln lt 60 fd :ln lt 120 fd :ln fd :ln lt 60 fd :ln rt 60]
end
to gl :st :ln
make "st :st - 1
make "ln :ln / sqrt 7
if :st > 0 [lt 60 rg :st :ln rt 60 gl :st :ln gl :st :ln rt 120 gl :st :ln rt 60 rg :st :ln lt 120 rg :st :ln lt 60 gl :st :ln]
if :st = 0 [lt 60 fd :ln rt 60 fd :ln fd :ln rt 120 fd :ln rt 60 fd :ln lt 120 fd :ln lt 60 fd :ln]
end
The program can be invoked, for example, with rg 4 300
, or alternatively gl 4 300
.
Python
A Python program, that uses the aforementioned L-System rules, to draw the Gosper curve using turtle graphics (online version):
import turtle
def gosper_curve(order: int, size: int, is_A: bool = True) -> None:
"""Draw the Gosper curve."""
if order == 0:
turtle.forward(size)
return
for op in "A-B--B+A++AA+B-" if is_A else "+A-BB--B-A++A+B":
gosper_op_map[op](order - 1, size)
gosper_op_map = {
"A": lambda o, size: gosper_curve(o, size, True),
"B": lambda o, size: gosper_curve(o, size, False),
"-": lambda o, size: turtle.right(60),
"+": lambda o, size: turtle.left(60),
}
size = 10
order = 3
gosper_curve(order, size)
Properties
The space filled by the curve is called the Gosper island. The first few iterations of it are shown below:
![]() |
![]() |
![]() |
![]() |
![]() |
The Gosper Island can tile the plane. In fact, seven copies of the Gosper island can be joined to form a shape that is similar, but scaled up by a factor of √7 in all dimensions. As can be seen from the diagram below, performing this operation with an intermediate iteration of the island leads to a scaled-up version of the next iteration. Repeating this process indefinitely produces a tessellation of the plane. The curve itself can likewise be extended to an infinite curve filling the whole plane.
![]() |
![]() |
See also
References
- ^ Weisstein, Eric W. "Peano-Gosper Curve". MathWorld. Retrieved 31 October 2013.
- ^ Uher, Vojtěch; Gajdoš, Petr; Snášel, Václav; Lai, Yu-Chi; Radecký, Michal (28 May 2019). "Hierarchical Hexagonal Clustering and Indexing". Symmetry. 11 (6): 731. doi:10.3390/sym11060731.
External links
- NEW GOSPER SPACE FILLING CURVES
- FRACTAL DE GOSPER (in French)
- Gosper Island at Wolfram MathWorld
- Flowsnake by R. William Gosper