Math::...Centres(3pm)
π Math::PlanePath::FlowsnakeCentres π
okay so bestie, welcome to the User Contributed Perl Documentation corner of the internet, where Math::PlanePath::FlowsnakeCentres(3pm) lives and honestly? she's iconic. let's get into it πβ¨
πΈ NAME πΈ
Math::PlanePath::FlowsnakeCentres β a self-similar path of hexagon centres. yes. that's the whole vibe. hexagons. centres. slay π
β¨ SYNOPSIS β¨
use Math::PlanePath::FlowsnakeCentres;
my $path = Math::PlanePath::FlowsnakeCentres->new;
my ($x, $y) = $path->n_to_xy (123);
three lines and you're in. no notes. π«Ά
π¦ DESCRIPTION π¦
okay so this path is a variation of the flowsnake curve by William Gosper β same tiling, same overall shape, but it goes through the centres of the hexagons instead of across the corners. so it's like, the same energy, but the base figure is symmetric. cute, right? π
39----40 8
/ \
32----33 38----37 41 7
/ \ \ \
31----30 34----35----36 42 47 6
\ / / \
28----29 16----15 43 46 48--... 5
/ / \ \ \
27 22 17----18 14 44----45 4
/ / \ \ \
26 23 21----20----19 13 10 3
\ \ / / \
25----24 4---- 5 12----11 9 2
/ \ /
3---- 2 6---- 7---- 8 1
\
0---- 1 <- Y=0
-5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9
the points get spread out on every second X coordinate so they make little triangles with integer coordinates β that's the "Triangular Lattice" situation described in Math::PlanePath, iykyk.
the base pattern is the seven points 0 to 6, and here she is in all her glory:
4---- 5
/ \
3---- 2 6---
\
0---- 1
this repeats at 7-fold increasing scale, and the sub-sections get rotated depending on the edge direction β and the 1, 2 and 6 sub-sections are in reverse. for example N=7 to N=13 is the "1" part taking the base figure in reverse and rotated so the end points towards the "2". it's giving choreography honestly π
the next level can be seen at the midpoints of each such group, being N=2,11,18,23,30,37,46:
---- 37
---- ---
30---- ---
| ---
| 46
|
| ----18
| ----- ---
23--- ---
---
--- 11
-----
2 ---
π Arms π
the optional "arms" parameter can give up to three copies of the curve, each advancing successively. for example "arms=>3" is as follows. notice the N=3*k points are the plain curve, and N=3*k+1 and N=3*k+2 are rotated copies of it. teamwork makes the dream work fr fr π
84---... 48----45 5
/ / \
81 66 51----54 42 4
/ / \ \ \
28----25 78 69 63----60----57 39 30 3
/ \ \ \ / / \
31----34 22 75----72 12----15 36----33 27 2
\ \ / \ /
40----37 19 4 9---- 6 18----21----24 1
/ / / \ \
43 58 16 7 1 0---- 3 77----80 <- Y=0
/ / \ \ \ / \
46 55 61 13----10 2 11 74----71 83 -1
\ \ \ / / \ \ \
49----52 64 73 5---- 8 14 65----68 86 -2
/ / \ / / /
... 67----70 76 20----17 62 53 ... -3
\ / / / / \
85----82----79 23 38 59----56 50 -4
/ / \ /
26 35 41----44----47 -5
\ \
29----32 -6
^
-9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9
as described in "Arms" in Math::PlanePath::Flowsnake, the flowsnake essentially fills a hexagonal shape with wiggly sides. for this Centres variation the start of each arm corresponds to the centre of a little hexagon. the N=0 little hexagon is at the origin, and the 1 and 2 are beside and below it, like:
^ / \ / \
\ \ / \
| \ | |
| 1 | 0--->
| | |
\ / \ /
\ / \ /
| |
| 2 |
| / |
/ /
v \ /
like the main Flowsnake, the sides of the arms mesh perfectly and three arms fill the plane. no gaps, no drama (well, some drama, it's gorgeous) π
π FUNCTIONS π
see "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. the shared lore, if you will π
$path = Math::PlanePath::FlowsnakeCentres->new ()β create and return a brand new path object. baby's first flowsnake πΌ($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. sorry bestie, no negatives π«
fractional positions give an X,Y position along a straight line between the integer positions. so you can get in between, it's giving in-between π«
($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)β in the current code the returned range is exact, meaning$n_loand$n_hiare the smallest and biggest in the rectangle, but don't rely on that yet since finding the exact range is a touch on the slow side. (the advantage of which though is that it helps avoid very big ranges from a simple over-estimate.) so like, it's accurate but it's taking its sweet time β³
π§ Level Methods π§
($n_lo, $n_hi) = $path->level_to_n_range($level)β return"(0, 7**$level - 1)", or for multiple arms return"(0, $arms * 7**$level - 1)".
there are 7^level points in a level, or arms*7^level for multiple arms, numbered starting from 0. math girlies rise up π’
π₯ FORMULAS π₯
β N to X,Y β
the "n_to_xy()" calculation follows Ed Schouten's method
<http://80386.nl/projects/flowsnake/>
breaking N into base-7 digits, applying reversals from high to low according to digits 1, 2, or 6, then applying rotation and position according to the resulting digits. it's a whole process but she's worth it π
unlike Ed's code, the path here starts from N=0 at the edge of the Gosper island shape and for that reason doesn't cover the plane. an offset of N-2*7^21 and suitable X,Y offset can be applied to get the same result. noted π
β X,Y to N β
the "xy_to_n()" calculation also follows Ed Schouten's method. it's based on a nice observation that the seven cells of the base figure can be identified from their X,Y coordinates, and the centre of those seven cell figures then shrunk down a level to be a unit apart, thus generating digits of N from low to high. big brain behaviour π§ β¨
in triangular grid X,Y a remainder is formed
m = (x + 2*y) mod 7
taking the base figure's N=0 at 0,0 the remainders are
4---- 6
/ \
1---- 3 5
\
0---- 2
the remainders are unchanged when the shape is moved by some multiple of the next level X=5,Y=1 or the same at 120 degrees X=1,Y=3 or 240 degrees X=-4,Y=1. those vectors all have X+2*Y==0 mod 7. consistency queen π
from the m remainder an offset can be applied to move X,Y to the 0 position, leaving X,Y a multiple of the next level vectors X=5,Y=1 etc. those vectors can then be shrunk down with
Xshrunk = (3*Y + 5*X) / 14
Yshrunk = (5*Y - X) / 14
this gives integers since 3*Y+5*X and 5*Y-X are always multiples of 14. for example the N=35 point at X=2,Y=6 reduces to X = (3*6+5*2)/14 = 2 and Y = (5*6-2)/14 = 2, which is then the "5" part of the base figure. the math is mathing π’π
the remainders can be mapped to digits and then reversals and rotations applied, from high to low, according to the edge orientation. those steps can be combined in a single lookup table with 6 states (three rotations, and each one forward or reverse). efficient and stunning π«
for the main curve the reduction ends at 0,0. for the multi-arm form the second arm ends to the right at -2,0 and the third below at -1,-1. notice the modulo and shrink procedure maps those three points back to themselves unchanged. the calculation can be done without paying attention to which arms are supposed to be in use. on reaching one of the three ends the "arm" is determined and the original X,Y can be rejected or accepted accordingly. very demure, very mindful πΈ
the key to this approach is that the base figure is symmetric around a central point, so the tiling can be broken down first, and the rotations or reversals in the path applied afterwards. can it work on a non-symmetric base figure like the "across" style of the main Flowsnake, or something like the "DragonCurve" for that matter? open question, bestie. someone go find out π
π SEE ALSO π
Math::PlanePath,Math::PlanePath::Flowsnake,Math::PlanePath::GosperIslandsMath::PlanePath::KochCurve,Math::PlanePath::HilbertCurve,Math::PlanePath::PeanoCurve,Math::PlanePath::ZOrderCurve<http://80386.nl/projects/flowsnake/>β Ed Schouten's code
the whole friend group, honestly π«
π HOME PAGE π
<http://user42.tuxfamily.org/math-planepath/index.html>
come through π‘β¨
π 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. (yes, this part is serious β no warranty, fr fr π)
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 is Math::...Centres(3pm) from the User Contributed Perl Documentation, perl v5.32.0, dated 2021-01-23. go forth and plot hexagon centres, you absolute icon ππ¦
π¦ 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