Math::...lCurve(3pm)
π Math::PlanePath::KochelCurve β the manual, but make it make sense π
okay bestie, buckle up, because we're talking about Math::PlanePath::KochelCurve, which lives in the User Contributed Perl Documentation (that's the manual name, iykyk) and it is genuinely one of the cutest little space-filling curves you will ever meet. no cap. π
β¨ NAME β¨
Math::PlanePath::KochelCurve β a 3x3 self-similar R and F situation, and yes the "R" and "F" are the whole personality here. π
πΈ SYNOPSIS πΈ
use Math::PlanePath::KochelCurve;
my $path = Math::PlanePath::KochelCurve->new;
my ($x, $y) = $path->n_to_xy (123);
literally three lines and you're in. iconic behavior. β¨
π¦ DESCRIPTION π¦
so this is an integer version of the Kochel curve, invented by:
Herman Haverkort, "Recursive Tilings and Space-Filling Curves with Little Fragmentation", Journal of Computational Geometry, volume 2, number 1, 2011, pages 92-127.
<http://jocg.org/index.php/jocg/article/view/68>, <http://jocg.org/index.php/jocg/article/download/68/20>, <http://arxiv.org/abs/1002.1843>
<http://alexandria.tue.nl/openaccess/Metis239505.pdf> (slides), <http://www.win.tue.nl/~hermanh/stack/h-rtslf-eurocg2010-talk.pdf> (short form)
the way that it fills the first quadrant in a 3x3 self-similar pattern made from two base shapes?? obsessed. π€©
|
8 80--79 72--71--70--69 60--59--58
| | | | |
7 77--78 73 66--67--68 61 56--57
| | | | |
6 76--75--74 65--64--63--62 55--54
|
5 11--12 17--18--19--20 47--48 53
| | | | | | |
4 10 13 16 25--24 21 46 49 52
| | | | | | | | |
3 9 14--15 26 23--22 45 50--51
| | |
2 8-- 7-- 6 27--28--29 44--43--42
| | |
1 1-- 2 5 32--31--30 37--38 41
| | | | | | |
Y=0-> 0 3-- 4 33--34--35--36 39--40
X=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
so the two base shapes are an "R" and an "F". the R goes along an edge, and the F goes diagonally across. that's it, that's the lore. π«Ά
R pattern F pattern ^
+------+-----+-----+ +------+-----+----|+
|2 | |3\ |4 | |2 | |3\ |8 ||
| R | | F | R | | R | | F | R ||
| | | \ |-----| | | | \ | ||
+------+-----+-----+ +------+-----+-----+
|1 / |6 |5 / | |1 / |4 / |7 / |
| F | Rrev| F | | F | F | F |
| / |-----| / | | / | / | / |
+------+-----+-----+ +------+-----+-----+
|0| |7\ |8 | |0| |5\ ||6 |
| |Rrev| F | R | | |Rrev| F ||Rrev|
| o | \ |------> | o | \ || |
+------+-----+-----+ +------+-----+-----+
"Rrev" means the R pattern followed in reverse, which looks like this:
+------+-----+-----+
|8<----|7\ |6 | Rrev pattern
| R | F | Rrev|
| | \ |-----| turned -90 degrees
+------+-----+-----+ so as to start at
|1 / ||2 |5 / | bottom left
| F || R | F |
| / || | / |
+------+-----+-----+
|0| |3\ ||4 |
| |Rrev| F ||Rrev|
| o | \ || |
+------+-----+-----+
the F pattern is symmetric β same forward or reverse, including its sub-parts taken in reverse β so there's no separate "Frev" pattern. queen doesn't need an understudy. π
the initial N=0 to N=8 is the Rrev turned -90, then N=9 to N=17 is the F shape. the next higher level N=0,N=9,N=18 to N=72 is the Rrev too, as is any N=9^k to N=8*9^k. periodt. π₯
π§ Fractal π§
the curve is conceived by Haverkort for filling a unit square by descending into ever-smaller replacements, similar to other space-filling curves. for that, the top-level can be any of the patterns. but for the outward expanding version here, the starting pattern must occur at the start of its next higher level, which means Rrev is the only choice as it's the only start in any of the three patterns. no other option was available bestie, that's just the math. π
all the patterns can be found in the path at any desired size. for example the "1" part of Rrev is an F, which means F to a desired level can be found at:
NFstart = 1 * 9^level
NFlast = NFstart + 9^level - 1
= 2 * 9^level - 1
XFstart = 3^level
YFstart = 0
level=3 for N=729 to N=1457 is a 27x27 which is the level-three F shown in Haverkort's paper, starting at XFstart=27,YFstart=0. look at her go β¨
π FUNCTIONS π
see "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. (yes, all the path classes share the same brain cell, and it's a big one π§ )
$path = Math::PlanePath::KochelCurve->new ()β create and return a new path object. your very own baby. πΌ($x,$y) = $path->n_to_xy ($n)β return the X,Y coordinates of point number$non the path. points begin at0, and if$n < 0then the return is an empty list. so don't come at her with negatives, she will simply give you nothing. π
β Level Methods β
($n_lo, $n_hi) = $path->level_to_n_range($level)β return(0, 9**$level - 1). that's the whole range, no crumbs. π
π SEE ALSO π
Math::PlanePathMath::PlanePath::PeanoCurveMath::PlanePath::WunderlichMeander
(the whole squad, go say hi π«Ά)
π HOME PAGE π
<http://user42.tuxfamily.org/math-planepath/index.html>
π LICENSE π
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde
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.
you should have received a copy of the GNU General Public License along with Math-PlanePath. if not, see <http://www.gnu.org/licenses/>.
β οΈ bestie, that warranty disclaimer is not a joke β no promises, no guarantees, that's the deal. π
and that's the whole page!! this gorgeous thing is from perl v5.32.0, dated 2021-01-23, and it is filed under Math::...lCurve(3pm). slay, mwah, 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