1Math::PlanePath::KochSqUusaerrefCloanktersi(b3u)ted PerlMaDtohc:u:mPelnatnaetPiaotnh::KochSquareflakes(3)
2
3
4
6 Math::PlanePath::KochSquareflakes -- four-sided Koch snowflakes
7
9 use Math::PlanePath::KochSquareflakes;
10 my $path = Math::PlanePath::KochSquareflakes->new (inward => 0);
11 my ($x, $y) = $path->n_to_xy (123);
12
14 This is the Koch curve shape arranged as four-sided concentric
15 snowflakes.
16
17 61 10
18 / \
19 63-62 60-59 9
20 | |
21 67 64 58 55 8
22 / \ / \ / \
23 69-68 66-65 57-56 54-53 7
24 | |
25 70 52 6
26 / \
27 71 51 5
28 \ /
29 72 50 4
30 | |
31 73 15 49 3
32 / / \ \
33 75-74 17-16 14-13 48-47 2
34 | | | |
35 76 18 12 46 1
36 / / 4---3 \ \
37 77 19 . | 11 45 Y=0
38 \ \ 1---2 / /
39 78 20 10 44 -1
40 | | |
41 79-80 5--6 8--9 42-43 -2
42 \ \ / /
43 81 7 41 -3
44 | |
45 82 40 -4
46 / \
47 83 39 -5
48 \ /
49 84 38 -6
50 |
51 21-22 24-25 33-34 36-37 -7
52 \ / \ / \ /
53 23 26 32 35 -8
54 | |
55 27-28 30-31 -9
56 \ /
57 29 -10
58
59 ^
60 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9 10
61
62 The innermost square N=1 to N=4 is the initial figure. Its sides
63 expand as the Koch curve pattern in subsequent rings. The initial
64 figure is on X=+/-0.5,Y=+/-0.5 fractions. The points after that are
65 integer X,Y.
66
68 The "inward=>1" option can direct the sides inward. The shape and
69 lengths etc are the same. The angles and sizes mean there's no
70 overlaps.
71
72 69-68 66-65 57-56 54-53 7
73 | \ / \ / \ / |
74 70 67 64 58 55 52 6
75 \ | | /
76 71 63-62 60-59 51 5
77 / \ / \
78 72 61 50 4
79 | |
80 73 49 3
81 \ /
82 74-75 17-16 14-13 47-48 2
83 | | \ / | |
84 76 18 15 12 46 1
85 \ \ 4--3 / /
86 77 19 |11 45 <- Y=0
87 / / 1--2 \ \
88 78 20 7 10 44 -1
89 | / \ | |
90 80-79 5--6 8--9 43-42 -2
91 / \
92 81 41 -3
93 | |
94 82 29 40 -4
95 \ / \ /
96 83 27-28 30-31 39 -5
97 / | | \
98 84 23 26 32 35 38 -6
99 / \ / \ / \ |
100 21-22 24-25 33-34 36-37 -7
101
102 ^
103 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7
104
105 Level Ranges
106 Counting the innermost N=1 to N=4 square as level 0, a given level has
107
108 looplen = 4*4^level
109
110 many points. The start of a level is N=1 plus the preceding loop
111 lengths so
112
113 Nstart = 1 + 4*[ 1 + 4 + 4^2 + ... + 4^(level-1) ]
114 = 1 + 4*(4^level - 1)/3
115 = (4^(level+1) - 1)/3
116
117 and the end of a level similarly the total loop lengths, or simply one
118 less than the next Nstart,
119
120 Nend = 4 * [ 1 + ... + 4^level ]
121 = (4^(level+2) - 4) / 3
122
123 = Nstart(level+1) - 1
124
125 For example,
126
127 level Nstart Nend (A002450,A080674)
128 0 1 4
129 1 5 20
130 2 21 84
131 3 85 340
132
133 The Xstart,Ystart position of the Nstart corner is a Lucas sequence,
134
135 Xstart(0) = -0.5
136 Xstart(1) = -2
137 Xstart(2) = 4*Xstart(1) - 2*Xstart(0) = -7
138 Xstart(3) = 4*Xstart(2) - 2*Xstart(1) = -24
139 ...
140 Xstart(level+1) = 4*Xstart(level) - 2*Xstart(level-1)
141
142 0.5, 2, 7, 24, 82, 280, 956, 3264, ... (A003480)
143
144 This recurrence occurs because the replications are 4 wide when
145 horizontal but 3 wide when diagonal.
146
148 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
149 classes.
150
151 "$path = Math::PlanePath::KochSquareflakes->new ()"
152 "$path = Math::PlanePath::KochSquareflakes->new (inward => $bool)"
153 Create and return a new path object.
154
155 Level Methods
156 "($n_lo, $n_hi) = $path->level_to_n_range($level)"
157 Return per "Level Ranges" above,
158
159 ( (4**$level - 1)/3,
160 4*(4**$level - 1)/3 )
161
163 Entries in Sloane's Online Encyclopedia of Integer Sequences related to
164 this path include
165
166 <http://oeis.org/A003480> (etc)
167
168 A003480 -X and -Y coordinate first point of each ring
169 likewise A020727
170 A007052 X,Y coordinate of axis crossing,
171 and also maximum height of a side
172 A072261 N on Y negative axis (half way along first side)
173 A206374 N on South-East diagonal (end of first side)
174
176 Math::PlanePath, Math::PlanePath::KochSnowflakes
177
179 <http://user42.tuxfamily.org/math-planepath/index.html>
180
182 Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 Kevin Ryde
183
184 Math-PlanePath is free software; you can redistribute it and/or modify
185 it under the terms of the GNU General Public License as published by
186 the Free Software Foundation; either version 3, or (at your option) any
187 later version.
188
189 Math-PlanePath is distributed in the hope that it will be useful, but
190 WITHOUT ANY WARRANTY; without even the implied warranty of
191 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
192 General Public License for more details.
193
194 You should have received a copy of the GNU General Public License along
195 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
196
197
198
199perl v5.28.0 2017-12-0M3ath::PlanePath::KochSquareflakes(3)