1Math::PlanePath::TerdraUgsoenrMiCdopnotirnitb(u3t)ed PerMlatDho:c:uPmleannteaPtaitohn::TerdragonMidpoint(3)
2
3
4
6 Math::PlanePath::TerdragonMidpoint -- dragon curve midpoints
7
9 use Math::PlanePath::TerdragonMidpoint;
10 my $path = Math::PlanePath::TerdragonMidpoint->new;
11 my ($x, $y) = $path->n_to_xy (123);
12
14 This is midpoints of an integer version of the terdragon curve by Davis
15 and Knuth.
16
17 30----29----28----27 13
18 \ /
19 31 26 12
20 \ /
21 36----35----34----33----32 25 11
22 \ /
23 37 41 24 10
24 \ / \ /
25 38 40 42 23----22----21 9
26 \ / \ /
27 39 43 20 8
28 \ /
29 48----47----46----45----44 19 12----11----10-----9 7
30 \ / \ /
31 49 18 13 8 6
32 \ / \ /
33 ...---50 17----16----15----14 7 5
34 /
35 6 4
36 /
37 5-----4-----3 3
38 /
39 2 2
40 /
41 1 1
42 /
43 0 <- Y=0
44
45 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
46 -12-11-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 ...
47
48 The points are the middle of each edge of a double-size
49 "TerdragonCurve".
50
51 ...
52 \
53 6 -----8----- double size
54 \ TerdragonCurve
55 \ giving midpoints
56 5 7
57 \
58 \
59 4 -----6---- _
60 \ / \
61 \ / \
62 3 5 4 3
63 \ / \
64 \_/ \
65 2 _----2-----
66 \
67 \
68 1 1
69 \
70 \
71 Y=0 -> +-----0-----.
72
73 ^
74 X=0 1 2 3 4 5 6
75
76 For example in the "TerdragonCurve" N=3 to N=4 is X=3,Y=1 to X=2,Y=2
77 and that's doubled out here to X=6,Y=2 and X=4,Y=4 then the midpoint of
78 those positions is X=5,Y=3 for N=3 in the "TerdragonMidpoint".
79
80 The result is integer X,Y coordinates on every second point per
81 "Triangular Lattice" in Math::PlanePath, but visiting only 3 of every 4
82 such triangular points, which in turn is 3 of 8 all integer X,Y points.
83 The points used are a pattern of alternate rows with 1 of 2 points and
84 1 of 4 points. For example the Y=7 row is 1 of 2 and the Y=8 row is 1
85 of 4. Notice the pattern is the same when turned by 60 degrees.
86
87 * * * * * * * * * * * * * * * * * * * *
88 * * * * * * * * * *
89 * * * * * * * * * * * * * * * * * * * *
90 * * * * * * * * *
91 * * * * * * * * * * * * * * * * * * * *
92 * * * * * * * * * *
93 * * * * * * * * * * * * * * * * * * * *
94 * * * * * * * * *
95 * * * * * * * * * * * * * * * * * * * *
96 * * * * * * * * * *
97 * * * * * * * * * * * * * * * * * * * *
98 * * * * * * * * *
99 * * * * * * * * * * * * * * * * * * * *
100 * * * * * * * * * *
101 * * * * * * * * * * * * * * * * * * * *
102
103 Arms
104 Multiple copies of the curve can be selected, each advancing
105 successively. Like the main "TerdragonCurve" the midpoint curve covers
106 1/6 of the plane and 6 arms rotated by 60, 120, 180, 240 and 300
107 degrees mesh together perfectly. With 6 arms all the alternating
108 "1of2" and "1of4" points described above are visited.
109
110 "arms => 6" begins as follows. N=0,6,12,18,etc is the first arm (like
111 the single curve above), then N=1,7,13,19 the second copy rotated 60
112 degrees, N=2,8,14,20 the third rotated 120, etc.
113
114 arms=>6 ...
115 /
116 ... 42
117 \ /
118 43 19 36
119 \ / \ /
120 37 25 13 30----24----18
121 \ / \ /
122 31 7 12
123 \ /
124 20----14-----8-----2 1 6 35----41----47-..
125 \ / \
126 26 3 . 0 29
127 \ / \
128 ..-44----38----32 9 4 5----11----17----23
129 / \
130 15 10 34
131 / \ / \
132 21----27----33 16 28 40
133 / \ / \
134 39 22 46
135 / \
136 45 ...
137 /
138 ...
139
141 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
142 classes.
143
144 "$path = Math::PlanePath::TerdragonMidpoint->new ()"
145 Create and return a new path object.
146
147 "($x,$y) = $path->n_to_xy ($n)"
148 Return the X,Y coordinates of point number $n on the path. Points
149 begin at 0 and if "$n < 0" then the return is an empty list.
150
151 Fractional positions give an X,Y position along a straight line
152 between the integer positions.
153
154 "$n = $path->n_start()"
155 Return 0, the first N in the path.
156
157 Level Methods
158 "($n_lo, $n_hi) = $path->level_to_n_range($level)"
159 Return "(0, 3**$level - 1)", or for multiple arms return "(0, $arms
160 * 3**$level - 1)".
161
162 There are 3^level segments comprising the terdragon, or
163 arms*3^level when multiple arms, numbered starting from 0.
164
166 X,Y to N
167 An X,Y point can be turned into N by dividing out digits of a complex
168 base b=w+1 where
169
170 w = 1/2 + i * sqrt(3)/2 w^2 w
171 = 6th root of unity \ /
172 \ /
173 w^3=-1 -----o------ w^0=1
174 / \
175 / \
176 w^4 w^5
177
178 At each step the low ternary digit is formed from X,Y and an adjustment
179 applied to move X,Y onto a multiple of w+1 ready to divide out w+1.
180
181 In the N points above it can be seen that each group of three N values
182 make a straight line, such as N=0,1,2, or N=3,4,5 etc. The adjustment
183 moves the two ends N=0mod3 or N=2mod3 to the centre N=1mod3. The
184 centre N=1mod3 position is always a multiple of w+1.
185
186 The angles and positions for the N triples follow a 12-point pattern as
187 follows, where each / \ or - is a point on the path (any arm).
188
189 \ / / \ / / \ / / \ / / \
190 - \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
191 / \ / / \ / / \ / / \ /
192 \ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
193 \ / / \ / / \ / / \ / / \
194 - \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
195 / \ / / \ / / \ / / \ /
196 \ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
197 \ / / \ / / \ / / \ / / \
198 - \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
199 / \ / / \ / / \ / / \ /
200 \ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
201 \ / / \ / / \ / / \ / / \
202 - \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
203 / \ / / \ / / \ / / \ /
204 \ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
205 \ / / \ / / \ / / \ / / \
206 - \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
207 / \ / / \ / / \ / / \ /
208 \ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
209 \ / / \ / / \ / / \ / / \
210 - \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
211 / \ / / \ / / \ / / \ /
212 \ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
213
214 In the current code a 12x12 table is used, indexed by X mod 12 and Y
215 mod 12. With Xadj and Yadj from there
216
217 Ndigit = (X + 1) mod 3 # N digits low to high
218
219 Xm = X + Xadj[X mod 12, Y mod 12]
220 Ym = Y + Yadj[X mod 12, Y mod 12]
221
222 new X,Y = (Xm,Ym) / (w+1)
223 = (Xm,Ym) * (2-w) / 3
224 = ((Xm+Ym)/2, (Ym-(Xm/3))/2)
225
226 Is there a good aX+bY mod 12 or mod 24 for a smaller table? Maybe X+3Y
227 like the digit? Taking C=(X-Y)/2 in triangular coordinate style can
228 reduce the table to 6x6.
229
230 Points not reached by the curve (ie. not the 3 of 4 triangular or 3 of
231 8 rectangular described above) can be detected with "undef" or suitably
232 tagged entries in the adjustment table.
233
234 The X,Y reduction stops at the midpoint of the first triple of the
235 originating arm. So X=3,Y=1 which is N=1 for the first arm, and that
236 point rotated by 60,120,180,240,300 degrees for the others. If only
237 some of the arms are of interest then reaching one of the others means
238 the original X,Y was outside the desired region.
239
240 Arm X,Y Endpoint
241 --- ------------
242 0 3,1
243 1 0,2
244 2 -3,1
245 3 -3,-1
246 4 0,-2
247 5 3,-1
248
249 For the odd arms 1,3,5 each digit of N must be flipped 2-digit so 0,1,2
250 becomes 2,1,0,
251
252 if arm odd
253 then N = 3**numdigits - 1 - N
254
256 Math::PlanePath, Math::PlanePath::TerdragonCurve,
257 Math::PlanePath::TerdragonRounded
258
259 Math::PlanePath::DragonMidpoint, Math::PlanePath::R5DragonMidpoint
260
262 <http://user42.tuxfamily.org/math-planepath/index.html>
263
265 Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020
266 Kevin Ryde
267
268 This file is part of Math-PlanePath.
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.38.0 2023-07-M2a0th::PlanePath::TerdragonMidpoint(3)