The algorithm for generating a figure consists of 2 phases. In the first phase a recipe of directions will be made. In the second phase the recipe is applied for constructing the figure.
The
algorithm can best be illustrated by using an rational number,
being the ratio of a numerator N and a denominator D. For the
moment, N is assumed to be odd, and D even; and also, the
value of D
is less than N. Furthermore, without loss of generality, both numbers
are relatively prime.
The recipe
is a sequence of directions,
named { a0, a1,
... , aN-1 }. An element
in the sequence is either R (right) or L (left). It is
computed by comparing multiples of D with multiples of N.
The rule for ak is as
follows:
the direction of element ak with index
k equals
R, if k*D mod(2*N) < N, and
it equals L, if
k*D mod(2*N) >= N .
For example,
D=2, N=5 yields recipe RRRLL . After N directions a full cycle has been
made due
to D being even. The length of the recipe is N. It consists always of
(N+1)/2
directions R, and (N-1)/2 directions L.
In the
second
phase a plane is used, that is virtually tiled with equilateral
triangles.
The
middle of a certain triangle is chosen as the start point of the
figure, as follows:
One
of the 3
neighbouring triangles is selected for fixing the
orientation. From the start point a line is drawn to the middle of one
of the 2
other triangles. The choice for the 2 neighbours is determined by the
recipe at
phase 1. Relative to the current orientation we turn to the right if
the direction in the recipe equals R, and otherwise we turn to
the left.
The drawn
line is used as new orientation for drawing the next line. After
processing the
whole recipe the last line will point to 4 o' clock, see below:
Applying the above procedure another 5 times brings us back at the start point! This concludes the construction of the figure. For the above example, the complete figure looks like :
The following remarks can be made about the above algorithm.