1Math::PlanePath::GosperUIsselranCdosn(t3r)ibuted Perl DoMcautmhe:n:tPaltainoenPath::GosperIslands(3)
2
3
4
6 Math::PlanePath::GosperIslands -- concentric Gosper islands
7
9 use Math::PlanePath::GosperIslands;
10 my $path = Math::PlanePath::GosperIslands->new;
11 my ($x, $y) = $path->n_to_xy (123);
12
14 This path is integer versions of the Gosper island at successive
15 levels, arranged as concentric rings on a triangular lattice (see
16 "Triangular Lattice" in Math::PlanePath). Each island is the outline
17 of a self-similar tiling of the plane by hexagons, and the sides are
18 self-similar expansions of line segments
19
20 35----34 8
21 / \
22 ..-36 33----32 29----28 7
23 \ / \
24 31----30 27----26 6
25 \
26 25 5
27
28 78 4
29 \
30 11-----10 77 3
31 / \ /
32 13----12 9---- 8 76 2
33 / \ \
34 14 3---- 2 7 ... 1
35 \ / \
36 15 4 1 24 <- Y=0
37 / \ \
38 16 5----- 6 23 -1
39 \ /
40 17----18 21----22 -2
41 \ /
42 19----20 -3
43
44
45
46
47 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9 10 11
48
49 Hexagon Replications
50 The islands can be thought of as a self-similar tiling of the plane by
51 hexagonal shapes. The innermost hexagon N=1 to N=6 is replicated six
52 times to make the next outline N=7 to N=24.
53
54 *---*
55 / \
56 *---* *---*
57 / \ / \
58 * *---* *
59 \ / \ /
60 *---* *---*
61 / \ / \
62 * *---* *
63 \ / \ /
64 *---* *---*
65 \ /
66 *---*
67
68 Then that shape is in turn replicated six times around itself to make
69 the next level.
70
71 *---E
72 / \
73 *---* *---* *---*
74 / \ / \
75 * *---* *---*
76 \ / \
77 * * D
78 / \ /
79 *---* * *
80 / \ / \
81 *---* *---* *---* *
82 / \ / \ /
83 * *---* *---* *---*
84 \ / \ / \
85 * * C---* *---*
86 / \ / \
87 * * O * *
88 \ / \ /
89 *---* *---* * *
90 \ / \ / \
91 *---* *---* *---* *
92 / \ / \ /
93 * *---* *---* *---*
94 \ / \ /
95 * * *---*
96 / \ /
97 * * *
98 \ / \
99 *---* *---* *
100 \ / \ /
101 *---* *---* *---*
102 \ /
103 *---*
104
105 The shapes here and at higher level are like hexagons with wiggly
106 sides. The sides are symmetric, so they mate on opposite sides but the
107 join "corner" is not on the X axis (after the first level). For
108 example the point marked "C" (N=7) is above the axis at X=5,Y=1. The
109 next replication joins at point "D" (N=25) at X=11,Y=5.
110
111 Side and Radial Lines
112 The sides at each level is a self-similar line segment expansion,
113
114 *---*
115 *---* becomes /
116 *---*
117
118 This expanding side shape is also the radial line or spoke from the
119 origin out to "corner" join points. At level 0 they're straight lines,
120
121 ...----*
122 / \
123 / \ side
124 / \
125 / \
126 O---------*
127 /
128 /
129
130 Then at higher levels they're wiggly, such as level 1,
131
132 ...--*
133 / \
134 * *---*
135 \ \
136 * *---C
137 / / /
138 O---* ...
139
140 Or level 2,
141
142 *---E
143 ... / \
144 * *---* *---*
145 \ \ / \
146 * *---* *---*
147 / \
148 * *---D
149 \ / /
150 *---* *---* ...
151 \ /
152 * *
153 / \
154 * *
155 \ /
156 * *---C
157 / /
158 O---*
159
160 The lines become ever wigglier at higher levels, and in fact become "S"
161 shapes with the ends spiralling around and in (and in fact middle
162 sections likewise S and spiralling, to a lesser extent).
163
164 The spiralling means that the X axis is crossed multiple times at
165 higher levels. For example in level 11 X>0,Y=0 occurs 22 times between
166 N=965221 and N=982146. Likewise on diagonal lines X=Y and X=-Y which
167 are "sixths" of the initial hexagon.
168
169 The self-similar spiralling means the Y axis too is crossed multiple
170 times at higher levels. In level 11 again X=0,Y>0 is crossed 7 times
171 between N=1233212 and N=1236579. (Those N's are bigger than the X axis
172 crossing, because the Nstart position at level 11 has rotated around
173 some 210 degrees to just under the negative X axis.)
174
175 In general any radial straight line is crossed many times way
176 eventually.
177
178 Level Ranges
179 Counting the inner hexagon as level=0, the side length and whole ring
180 is
181
182 sidelen = 3^level
183 ringlen = 6 * 3^level
184
185 The starting N for each level is the total points preceding it, so
186
187 Nstart = 1 + ringlen(0) + ... + ringlen(level-1)
188 = 3^(level+1) - 2
189
190 For example level=2 starts at Nstart=3^3-2=25.
191
192 The way the side/radial lines expand as described above makes the
193 Nstart position rotate around at each level. N=7 is at X=5,Y=1 which
194 is angle
195
196 angle = arctan(1*sqrt(3) / 5)
197 = 19.106.. degrees
198
199 The sqrt(3) factor as usual turns the flattened integer X,Y coordinates
200 into proper equilateral triangles. The further levels are then
201 multiples of that angle. For example N=25 at X=11,Y=5 is 2*angle, or
202 N=79 at X=20,Y=18 at 3*angle.
203
204 The N=7 which is the first radial replication at X=5,Y=1, scaled to
205 unit sided equilateral triangles, has distance from the origin
206
207 d1 = hypot(5, 1*sqrt(3)) / 2
208 = sqrt(7)
209
210 The subsequent levels are powers of that sqrt(7),
211
212 Xstart,Ystart of the Nstart(level) position
213
214 d = hypot(Xstart,Ystart*sqrt(3))/2
215 = sqrt(7) ^ level
216
217 This multiple of the angle and powering of the radius means the Nstart
218 points are on a logarithmic spiral.
219
220 Fractal Island
221 The Gosper island is usually conceived as a fractal, with the initial
222 hexagon in a fixed position and the sides having the line segment
223 substitution described above, for ever finer levels of "S" spiralling
224 wiggliness. The code here can be used for that by rotating the Nstart
225 position back to the X axis and scaling down to a desired unit radius.
226
227 Xstart,Ystart of the Nstart(level) position
228
229 scale factor = 0.5 / hypot(Ystart*sqrt(3), Xstart)
230 rotate angle = - atan2 (Ystart*sqrt(3), Xstart)
231
232 This scale and rotate puts the Nstart point at X=1,Y=0 and further
233 points of the ring around from that. Remember the sqrt(3) factor on Y
234 for all points to turn the integer coordinates into proper equilateral
235 triangles.
236
237 Notice the line segment substitution doesn't change the area of the
238 initial hexagon. Effectively (and not to scale),
239
240 *
241 / \
242 *-------* becomes * / *
243 \ /
244 *
245
246 So the area lost below is gained above (or vice versa). The result is
247 a line of ever greater length enclosing an unchanging area.
248
250 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
251 classes.
252
253 "$path = Math::PlanePath::GosperIslands->new ()"
254 Create and return a new path object.
255
256 "($x,$y) = $path->n_to_xy ($n)"
257 Return the X,Y coordinates of point number $n on the path. Points
258 begin at 1 and if "$n < 0" then the return is an empty list.
259
261 Math::PlanePath, Math::PlanePath::KochSnowflakes,
262 Math::PlanePath::GosperSide
263
265 <http://user42.tuxfamily.org/math-planepath/index.html>
266
268 Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Kevin Ryde
269
270 Math-PlanePath is free software; you can redistribute it and/or modify
271 it under the terms of the GNU General Public License as published by
272 the Free Software Foundation; either version 3, or (at your option) any
273 later version.
274
275 Math-PlanePath is distributed in the hope that it will be useful, but
276 WITHOUT ANY WARRANTY; without even the implied warranty of
277 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
278 General Public License for more details.
279
280 You should have received a copy of the GNU General Public License along
281 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
282
283
284
285perl v5.30.0 2019-08-17 Math::PlanePath::GosperIslands(3)