Math::...idpoint(3pm)
π Math::...idpoint(3pm) π
okay bestie come SIT DOWN because this is the Math::...idpoint(3pm) page, straight out of the User Contributed Perl Documentation, and it's literally about a dragon. Not a real dragon. A curve dragon. But honestly? Still iconic. πβ¨
β¨ NAME β¨
Math::PlanePath::R5DragonMidpoint β the R5 dragon curve midpoints. that's it, that's the name, slay π
π SYNOPSIS π
use Math::PlanePath::R5DragonMidpoint;
my $path = Math::PlanePath::R5DragonMidpoint->new;
my ($x, $y) = $path->n_to_xy (123);
three lines and you're already plotting, we love a low-effort queen π«Ά
πΈ DESCRIPTION πΈ
so this is the midpoints of the R5 dragon curve by Jorg Arndt. Jorg. he did that. π
31--30 11
| |
32 29 10
| |
51--50 35--34--33 28--27--26 9
| | | |
52 49 36--37--38 23--24--25 8
| | | |
55--54--53 48--47--46 41--40--39 22 7
| | | |
56--57--58 63--64 45 42 19--20--21 6
| | | | | |
81--80 59 62 65 44--43 18--17--16 11--10 5
| | | | | | | |
82 79 60--61 66--67--68 15 12 9 4
| | | | | |
..-83 78--77--76 71--70--69 14--13 8-- 7-- 6 3
| | |
75 72 3-- 4-- 5 2
| | |
74--73 2 1
|
0-- 1 <- Y=0
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3
look at that. a whole vibe. π
the points are the middle of each edge of the "R5DragonCurve", rotated -45 degrees, shrunk by sqrt(2). and shifted to the origin. okay so she's the main curve's midpoint era, got it. β¨
*--11--* *--7--* R5DragonCurve
| | | | and its midpoints
12 10 8 6
| | | |
*--17--*--13--*--9--*--5--*
| | | |
18 16 14 4
| | | |
..-* *--15--* *--3--*
|
2
|
+--1--*
π¦ Arms π¦
multiple copies of the curve can be selected, each advancing successively. like the main "R5DragonCurve", this midpoint curve covers 1/4 of the plane, and 4 arms rotated by 0, 90, 180, 270 degrees mesh together perfectly. with 4 arms, all integer X,Y points are visited. no gaps. immaculate. π
"arms => 4" begins as follows. N=0,4,8,12,16,etc is the first arm (the same shape as the plain curve above), then N=1,5,9,13,17 the second, N=2,6,10,14 the third, etc.
arms=>4 76--80-... 6
|
72--68--64 44--40 5
| | |
25--21 60 48 36 4
| | | | |
29 17 56--52 32--28--24 75--79 3
| | | | |
41--37--33 13-- 9-- 5 12--16--20 71 83 2
| | | | |
45--49--53 6-- 2 1 8 59--63--67 ... 1
| | | |
... 65--61--57 10 3 0-- 4 55--51--47 <- Y=0
| | | | |
81 69 22--18--14 7--11--15 35--39--43 -1
| | | | |
77--73 26--30--34 54--58 19 31 -2
| | | | |
38 50 62 23--27 -3
| | |
42--46 66--70--74 -4
|
...-82--78 -5
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
-6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5
π FUNCTIONS π
see "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. (that's the shared lore, bestie, we don't repeat it here π)
$path = Math::PlanePath::R5DragonMidpoint->new ()β create and return a new path object. fresh off the rack. ποΈ($x,$y) = $path->n_to_xy ($n)β return the X,Y coordinates of point number$non the path. points begin at0, and if"$n < 0"then the return is an empty list. (yeah, negative N gets nothing, she's not answering that call π)
fractional positions give an X,Y position along a straight line between the integer positions. like, the in-between tea. π
$n = $path->n_start()β return0, the first N in the path. zero, periodt. π
π§ Level Methods π§
($n_lo, $n_hi) = $path->level_to_n_range($level)β return"(0, 5**$level - 1)", or for multiple arms return"(0, $arms * 5**$level - 1)".
there are 5^level segments comprising the curve, or arms*5^level when multiple arms, numbered starting from 0. so much math, so little time. β
π₯ FORMULAS π₯
π X,Y to N π
an X,Y point can be turned into N by dividing out digits of a complex base 1+2i. at each step the low base-5 digit is formed from X,Y and an adjustment applied to move X,Y to a multiple of 1+2i ready to divide out. complex numbers said hi and honestly? they ate. π
a 10x10 table is used for the digit and adjustments, indexed by Xmod10 and Ymod10. there's probably an a*X+b*Y mod 5 or mod 20 for a smaller table. (probably!! we're just saying it out loud, no promises π₯) but in any case, once the adjustment is found the result is
Ndigit = digit_table[X mod 10, Y mod 10] # low to high
Xm = X + Xadj_table [X mod 10, Y mod 10]
Ym = Y + Yadj_table [X mod 10, Y mod 10]
new X,Y = (Xm,Ym) / (1+2i)
= (Xm,Ym) * (1-2i) / 5
= ((Xm+2*Ym)/5, (Ym-2*Xm)/5)
these X,Y reductions eventually reach one of the starting points for the four arms
X,Y endpoint Arm +---+---+
------------ --- | 2 | 1 | Y=1
0, 0 0 +---+---+
0, 1 1 | 3 | 0 | Y=0
-1, 1 2 +---+---+
-1, 0 3 X=-1 X=0
for arms 1 and 3 the digits must be flipped 4-digit, so 0,1,2,3,4 -> 4,3,2,1,0. the arm number and hence whether this flip is needed is not known until reaching the endpoint. the suspense... the drama... π
if arm odd
then N = 5^numdigits - 1 - N
if only some of the arms are of interest then reaching one of the other arm numbers means the original X,Y was outside the desired curve. soz. π
π SEE ALSO π
Math::PlanePath,Math::PlanePath::R5DragonCurveMath::PlanePath::DragonMidpoint,Math::PlanePath::TerdragonMidpoint
(the whole dragon family reunion πππ)
πΈ HOME PAGE πΈ
<http://user42.tuxfamily.org/math-planepath/index.html>
π LICENSE π
copyright 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde β Kevin, you legend, ten years of dragon midpoints, that's commitment π
this file is part of Math-PlanePath.
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.
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. (fr fr, no warranty, don't come for her π)
you should have received a copy of the GNU General Public License along with Math-PlanePath. if not, see <http://www.gnu.org/licenses/>.
and that's the whole page bestie!! π this shipped with perl v5.32.0, dated 2021-01-23, and it lives under the Math::...idpoint(3pm) header. mwah, go plot a dragon, ily, bye!! πβ¨π¦
π¦ 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