Math::...W2Curve(3pm)

πŸ“¦
version 129 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Math::PlanePath::AR2W2Curve πŸ’–

okay bestie, welcome to the Math::PlanePath::AR2W2Curve page, straight out of the User Contributed Perl Documentation section, manual name 3pm and all. this is the whole thing, no skips, no cap. πŸ’…


✨ NAME ✨

Math::PlanePath::AR2W2Curve β€” a 2x2 self-similar curve made of four patterns. it's giving geometric art project and we are OBSESSED. πŸ¦‹


✨ SYNOPSIS ✨

use Math::PlanePath::AR2W2Curve;
my $path = Math::PlanePath::AR2W2Curve->new;
my ($x, $y) = $path->n_to_xy (123);

that's it, that's the whole vibe. load it, make a path, ask it for coordinates. slay. πŸŽ€


✨ DESCRIPTION ✨

so this is an integer version of the AR2W2 curve, and the source is iconic:

Asano, Ranjan, Roos, Welzl and Widmayer "Space-Filling Curves and Their Use in the Design of Geometric Data Structures", Theoretical Computer Science, volume 181, issue 1, pages 3-15, July 1997.

also in LATIN'95 Theoretical Informatics, which is at Google Books <http://books.google.com.au/books?id=_aKhJUJunYwC&pg=PA36>. πŸ’œ

it walks the first quadrant in self-similar 2x2 blocks that are a whole mixture of "U" and "Z" shapes. the whole point of mixing them up like that is to improve some locality measures β€” like, how big is the N range for a given region. main character behavior fr fr.

                                                |
             7     42--43--44  47--48--49  62--63
                     \      |   |       |   |
             6     40--41  45--46  51--50  61--60
                    |               |           |
             5     39  36--35--34  52  55--56  59
                    |   |    /      |   |   |   |
             4     38--37  33--32  53--54  57--58
                                 \
             3      6-- 7-- 8  10  31  28--27--26
                    |       |/  |   |   |       |
             2      5-- 4   9  11  30--29  24--25
                        |       |           |
             1      2-- 3  13--12  17--18  23--22
                     \      |       |   |       |
           Y=0 ->   0-- 1  14--15--16  19--20--21

                   X=0  1   2   3   4   5   6   7

look at her. she's literally ascending into the sky. 😭✨


🌸 Shape Parts 🌸

there's four base patterns, A to D. and here's the tea: A2 is a mirror image of A1, B2 is a mirror of B1, etc. etc. the start is A1, and above that comes D2, then A1 again β€” the two alternate back and forth. 🫢

                              ^---->                                ^
                2---3      C1 |  B2            1   3       C2    D1 |
           A1     \           |            A2  | \ |      ---->     |
                0---1          ^               0   2      ^    ---->
                           D2  | B1                       |B1    B2
                          ---->|                          |

                1---2      C2    B1             1---2      B2    C1
           B1   |   |     ---->---->        B2  |   |     ---->---->
                0   3     ^        |            0   3     ^        |
                          |D1    B2|                      |B1    D2|
                          |        v                      |        v

                             ^  \                            ^ |
                1---2      B1|   \A1            1---2     A2/  | B2
           C1   |   |        |    v         C2  |   |      /   v
                0   3       ^      |            0   3     ^      \
                           /A2   B2|                      |B1     \A1
                          /        v                      |        v

                             ^ |                              ^ \
               1---2      A2/  | C2              1---2     C1|  \A1
           D1  |   |       /   v            D2   |   |       |   v
               0   3      ^     \                0   3      ^      |
                          |D1    \A2                       /A1   D2|
                          |       v                       /        v

okay so for the parts that fill on the right β€” like the B1 and B2 sub-parts of A1 β€” the numbering has to be reversed. that doesn't change the shape of the curve itself, it's just how the enumeration works out here. important distinction, don't skip it. πŸ’€


🌈 Start Shape 🌈

the default starting shape is the A1 "Z" part, and above it sits D2. notice how the starting sub-part of D2 is A1, and the starting sub-part of A1 is D2 β€” so those two alternate at successive higher levels, forever, like they're in a situationship. their sub-parts reach all the other parts, in all directions, forward or reverse. πŸ’«

you can pick a different starting shape with the start_shape => $str option. the choices are:

    "A1"       \ pair
    "D2"       /
    "B2"       \ pair
    "B1rev"    /
    "D1rev"    \ pair
    "A2rev"    /

B2 begins with a reversed B1, and a B1 reverse begins with B2 (no reverse) β€” so those two alternate too. similarly, D1 reverse starts with A2 reverse, and A2 reverse starts with D1 reverse. cute little pairs. πŸŽ€

the authors conceived the curve as descending into ever-smaller sub-parts, and for that any of the patterns could be a top-level start. but to expand outwards like we do here, the starting part has to be the start of the pattern above it β€” and that's only true for the 6 listed. the descent graph is:

              D2rev ----->  D2 <--> A1
              B2rev ----->

    C2rev --> A1rev ----->  B2 <--> B1rev  <----- C2
              C1rev ----->                 <----- A2 <-- C1

              B1 ----->  D1rev <--> A2rev
              D1 ----->

so for example B1 is not at the start of anything. or A1rev is at the start of C2rev, but then nothing starts with C2rev. out of the 16 total, only the three pairs shown "<-->" are cycles, which means only those can extend upwards indefinitely. periodt. πŸ‘‘


✨ FUNCTIONS ✨

peep "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes, bestie. 🫢

  • $path = Math::PlanePath::AR2W2Curve->new () β€” creates and returns a brand new path object. newborn baby curve. 🍼
  • ($x,$y) = $path->n_to_xy ($n) β€” hands you the X,Y coordinates of point number $n on the path. points begin at 0, and if $n < 0 then the return is an empty list. no negativity allowed in this house. πŸ™ˆ
  • ($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2) β€” the returned range is exact, meaning $n_lo and $n_hi are the smallest and largest in the rectangle. precise queen behavior. πŸ’…

πŸ¦‹ Level Methods πŸ¦‹

  • ($n_lo, $n_hi) = $path->level_to_n_range($level) β€” returns (0, 4**$level - 1). that's it, that's the whole method. math is mathing. ✨

✨ SEE ALSO ✨

  • Math::PlanePath
  • Math::PlanePath::HilbertCurve
  • Math::PlanePath::PeanoCurve

go read those too, they're all iconic in their own ways. πŸ“šπŸ’–


✨ 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.

You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.

fr fr: the warranty disclaimer is NOT a joke, bestie. no warranty, no promises, read the license. 🫢

and that's a wrap! πŸ’œ this was perl v5.32.0, dated 2021-01-23, and it's the Math::...W2Curve(3pm) page β€” go forth and plot some gorgeous self-similar curves, you absolute legend. mwah. 😘✨