Math::...dpoint(3pm)
๐ Math::PlanePath::TerdragonMidpoint โ dragon curve midpoints ๐
okay bestie, buckle UP, because this is Math::PlanePath::TerdragonMidpoint from the User Contributed Perl Documentation (that's the 3pm manual, iykyk) and it is genuinely one of the cutest little plane-filling creatures you will ever meet. it's giving dragon. it's giving midpoint. it's giving "why is this so pretty" energy. let's go ๐โจ
โจ NAME โจ
Math::PlanePath::TerdragonMidpoint โ dragon curve midpoints ๐
๐ธ SYNOPSIS ๐ธ
use Math::PlanePath::TerdragonMidpoint;
my $path = Math::PlanePath::TerdragonMidpoint->new;
my ($x, $y) = $path->n_to_xy (123);
literally three lines and you're in. slay. ๐
๐ฆ DESCRIPTION ๐ฆ
so this is the midpoints of an integer version of the terdragon curve, by Davis and Knuth. (yes, that Knuth. iconic behavior. ๐)
30----29----28----27 13
\ /
31 26 12
\ /
36----35----34----33----32 25 11
\ /
37 41 24 10
\ / \ /
38 40 42 23----22----21 9
\ / \ /
39 43 20 8
\ /
48----47----46----45----44 19 12----11----10-----9 7
\ / \ /
49 18 13 8 6
\ / \ /
...---50 17----16----15----14 7 5
/
6 4
/
5-----4-----3 3
/
2 2
/
1 1
/
0 <- Y=0
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
-12-11-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 ...
the points are the middle of each edge of a double-size TerdragonCurve. periodt.
...
\
6 -----8----- double size
\ TerdragonCurve
\ giving midpoints
5 7
\
\
4 -----6---- _
\ / \
\ / \
3 5 4 3
\ / \
\_/ \
2 _----2-----
\
\
1 1
\
\
Y=0 -> +-----0-----.
^
X=0 1 2 3 4 5 6
so for example in the TerdragonCurve N=3 to N=4 is X=3,Y=1 to X=2,Y=2, and that's doubled out here to X=6,Y=2 and X=4,Y=4, and then the midpoint of those positions is X=5,Y=3 for N=3 in the TerdragonMidpoint. math? we love her. ๐งฎ๐
the result is integer X,Y coordinates on every second point per Triangular Lattice in Math::PlanePath, but visiting only 3 of every 4 such triangular points, which in turn is 3 of 8 all integer X,Y points. the points used are a pattern of alternate rows with 1 of 2 points and 1 of 4 points. for example the Y=7 row is 1 of 2 and the Y=8 row is 1 of 4. and notice โ the pattern is the same when turned by 60 degrees. lowkey obsessed with the symmetry ngl ๐
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
๐ Arms ๐
multiple copies of the curve can be selected, each advancing successively. like the main TerdragonCurve, the midpoint curve covers 1/6 of the plane and 6 arms rotated by 60, 120, 180, 240 and 300 degrees mesh together perfectly. with 6 arms, all the alternating 1of2 and 1of4 points described above are visited. ๐ซ
arms => 6 begins as follows. N=0,6,12,18,etc is the first arm (like the single curve above), then N=1,7,13,19 the second copy rotated 60 degrees, N=2,8,14,20 the third rotated 120, etc.
arms=>6 ...
/
... 42
\ /
43 19 36
\ / \ /
37 25 13 30----24----18
\ / \ /
31 7 12
\ /
20----14-----8-----2 1 6 35----41----47-..
\ / \
26 3 . 0 29
\ / \
..-44----38----32 9 4 5----11----17----23
/ \
15 10 34
/ \ / \
21----27----33 16 28 40
/ \ / \
39 22 46
/ \
45 ...
/
...
๐ FUNCTIONS ๐
see FUNCTIONS in Math::PlanePath for behaviour common to all path classes. (bestie, that's the shared lore. ๐)
$path = Math::PlanePath::TerdragonMidpoint->new ()โ create and return a new path object. fresh path, new you, main character energy โจ($x,$y) = $path->n_to_xy ($n)โ return the X,Y coordinates of point number$non the path. points begin at 0 and if$n < 0then the return is an empty list.
fractional positions give an X,Y position along a straight line between the integer positions.
$n = $path->n_start()โ return 0, the first N in the path.
๐ Level Methods ๐
($n_lo, $n_hi) = $path->level_to_n_range($level)โ return(0, 3**$level - 1), or for multiple arms return(0, $arms * 3**$level - 1).
there are 3^level segments comprising the terdragon, or arms*3^level when multiple arms, numbered starting from 0. ๐ข
๐ฅ FORMULAS ๐ฅ
๐ X,Y to N
an X,Y point can be turned into N by dividing out digits of a complex base b=w+1 where
w = 1/2 + i * sqrt(3)/2 w^2 w
= 6th root of unity \ /
\ /
w^3=-1 -----o------ w^0=1
/ \
/ \
w^4 w^5
at each step the low ternary digit is formed from X,Y and an adjustment applied to move X,Y onto a multiple of w+1 ready to divide out w+1. ๐
in the N points above it can be seen that each group of three N values make a straight line, such as N=0,1,2, or N=3,4,5 etc. the adjustment moves the two ends N=0mod3 or N=2mod3 to the centre N=1mod3. the centre N=1mod3 position is always a multiple of w+1. ๐ก
the angles and positions for the N triples follow a 12-point pattern as follows, where each / \ or - is a point on the path (any arm).
\ / / \ / / \ / / \ / / \
- \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
/ \ / / \ / / \ / / \ /
\ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
\ / / \ / / \ / / \ / / \
- \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
/ \ / / \ / / \ / / \ /
\ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
\ / / \ / / \ / / \ / / \
- \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
/ \ / / \ / / \ / / \ /
\ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
\ / / \ / / \ / / \ / / \
- \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
/ \ / / \ / / \ / / \ /
\ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
\ / / \ / / \ / / \ / / \
- \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
/ \ / / \ / / \ / / \ /
\ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
\ / / \ / / \ / / \ / / \
- \ / \ - - - \ / \ - - - \ / \ - - - \ / \ - - -
/ \ / / \ / / \ / / \ /
\ - - - \ / \ - - - \ / \ - - - \ / \ - - - \ / \
in the current code a 12x12 table is used, indexed by X mod 12 and Y mod 12. with Xadj and Yadj from there
Ndigit = (X + 1) mod 3 # N digits low to high
Xm = X + Xadj[X mod 12, Y mod 12]
Ym = Y + Yadj[X mod 12, Y mod 12]
new X,Y = (Xm,Ym) / (w+1)
= (Xm,Ym) * (2-w) / 3
= ((Xm+Ym)/2, (Ym-(Xm/3))/2)
is there a good aX+bY mod 12 or mod 24 for a smaller table? maybe X+3Y like the digit? taking C=(X-Y)/2 in triangular coordinate style can reduce the table to 6x6. (open question, bestie, we're workshopping ๐ง )
points not reached by the curve (ie. not the 3 of 4 triangular or 3 of 8 rectangular described above) can be detected with undef or suitably tagged entries in the adjustment table.
the X,Y reduction stops at the midpoint of the first triple of the originating arm. so X=3,Y=1 which is N=1 for the first arm, and that point rotated by 60,120,180,240,300 degrees for the others. if only some of the arms are of interest then reaching one of the others means the original X,Y was outside the desired region.
Arm X,Y Endpoint
--- ------------
0 3,1
1 0,2
2 -3,1
3 -3,-1
4 0,-2
5 3,-1
for the odd arms 1,3,5 each digit of N must be flipped 2-digit so 0,1,2 becomes 2,1,0,
if arm odd
then N = 3**numdigits - 1 - N
๐ SEE ALSO ๐
Math::PlanePath, Math::PlanePath::TerdragonCurve, Math::PlanePath::TerdragonRounded
Math::PlanePath::DragonMidpoint, Math::PlanePath::R5DragonMidpoint
๐ซถ HOME PAGE ๐ซถ
<http://user42.tuxfamily.org/math-planepath/index.html>
...and bestie, we're not done yet. part 2 is coming, don't go anywhere ๐
๐ LICENSE ๐
okay bestie, legal time, but make it cute โจ
- Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde
This file is part of Math-PlanePath ๐ฆ
๐ the actual license vibes ๐
Math-PlanePath is free software โ you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. periodt ๐
Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ๐
bestie the caps are not me being dramatic, that's literally how it's written, it's giving "we are not legally responsible for your vibes" ๐ญ
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>. ๐ซถ
perl v5.32.0 ยท 2021-01-23 ยท Math::...dpoint(3pm)
aaaand that's the whole page, bestie ๐ no cap, you just read the entire thing. go forth and slay your plane paths โจ๐ฆ๐ธ
๐ฆ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms