Math::...Centres(3pm)

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

πŸ’– Math::PlanePath::QuintetCentres πŸ’–

okay bestie, gather round, because this is Math::PlanePath::QuintetCentres(3pm) β€” a User Contributed Perl Documentation page, no cap β€” and it's literally about a self-similar "plus" shape centres curve. Iconic behaviour. Let's get into it 🫢


✨ NAME ✨

Math::PlanePath::QuintetCentres β€” self-similar "plus" shape centres. That's it, that's the whole name. Simple. Elegant. Slay.


🌸 SYNOPSIS 🌸

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

like, three lines and you're already plotting points. main character energy fr fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So this is a self-similar curve that traces out a "+" shape, same vibe as QuintetCurve, but instead of walking the squares it takes the centre of each square that the curve visits. Centres only, periodt.

                                                92                        12
                                              /  |
                   124-...                  93  91--90      88            11
                     |                        \       \   /   \
               122-123 120     102              94  82  89  86--87        10
                  \   /  |    /  |            /   /  |       |
                   121 119 103 101-100      95  81  83--84--85             9
                          \   \       \       \   \
               114-115-116 118 104  32  99--98  96  80  78                 8
                 |       |/   /   /  |       |/      |/   \
           112-113 110 117 105  31  33--34  97  36  79  76--77             7
              \   /   \       \   \       \   /   \      |
               111     109-108 106  30  42  35  38--37  75                 6
                             |/   /   /  |       |    /
                           107  29  43  41--40--39  74                     5
                                  \   \              |
                        24--25--26  28  44  46  72--73  70      68         4
                         |       |/      |/   \   \   /   \   /   \
                    22--23  20  27  18  45  48--47  71  56  69  66--67     3
                      \   /   \   /   \      |        /   \      |
                        21   6  19  16--17  49  54--55  58--57  65         2
                           /  \      |       |    \      |    /
                     4-- 5   8-- 7  15      50--51  53  59  64             1
                      \      |    /              |/      |    \
                 0-- 1   3   9  14              52      60--61  63     <- Y=0
                     |/      |    \                          |/
                     2      10--11  13                      62            -1
                                 |/
                                12                                        -2

                 ^
            -1  X=0  1   2   3   4   5   6   7   8   9  10  11  12  13

The base figure is the initial N=0 to N=4, and it fills a "+" shape like this:

          .....
          .   .
          . 4 .
          .  \.
      ........\....
      .   .   .\  .
      . 0---1 . 3 .
      .   . | ./  .
      ......|./....
          . |/.
          . 2 .
          .   .
          .....

πŸŽ€ Arms πŸŽ€

There's an optional "arms" parameter, and it can give you up to four copies of the curve, each one advancing successively. Not me being obsessed with "arms=>4":

                        69                     ...              7
                      /  |                        \
       121     113  73  65--61      53             120          6
      /   \   /   \   \       \   /   \           /
   ...     117 105-109  77  29  57  45--49     116              5
                 |    /   /  |       |            \
               101  81  25  33--37--41  96-100-104 112          4
                 |    \   \              |       |/
            50  97--93  85  21  13  88--92  80 108  72          3
          /  |       |/      |/   \   \   /   \   /   \
        54  46--42  89  10  17   5-- 9  84  24  76  64--68      2
          \      |    /  |       |        /   \      |
            58  38  14   6-- 2   1  16--20  32--28  60          1
          /      |    \               \      |    /
        62  30--34  22--18   3   0-- 4  12  36  56          <- Y=0
         |    \   /          |       |/      |    \
    70--66  78  26  86  11-- 7  19   8  91  40--44  52         -1
      \   /   \   /   \   \   /  |    /  |       |/
        74 110  82  94--90  15  23  87  95--99  48             -2
          /  |       |            \   \      |
       114 106-102--98  43--39--35  27  83 103                 -3
          \              |       |/   /      |
           118      51--47  59  31  79 111-107 119     ...     -4
          /           \   /   \       \   \   /   \   /
       122              55      63--67  75 115     123         -5
          \                          |/
           ...                      71                         -6

                                 ^
    -7  -6  -5  -4  -3  -2  -1  X=0  1   2   3   4   5   6

Notice how the N=4*k points are the plain curve, and N=4*k+1, N=4*k+2 and N=4*k+3 are rotated copies of it. The way it just... rotates? Obsessed.

The pattern is an ever expanding "+" shape with the first cell N=0 at the origin. The further parts are effectively as follows:

               +---+
               |   |
       +---+---    +---+
       |   |           |
   +---+   +---+   +---+
   |         2 | 1 |   |
   +---+   +---+---+   +---+
       |   | 3 | 0         |
       +---+   +---+   +---+
       |           |   |
       +---+   +---+---+
           |   |
           +---+

At higher replication levels the sides become wiggly and spiralling, but they're symmetric and mesh to fill the plane. lowkey gorgeous, highkey genius 🧚


πŸ‘‘ FUNCTIONS πŸ‘‘

See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. (Shared lore, iykyk.)

  • $path = Math::PlanePath::QuintetCentres->new ()
  • $path = Math::PlanePath::QuintetCentres->new (arms => $a)

Create and return a new path object. Your very own path bestie πŸ’œ

  • ($x,$y) = $path->n_to_xy ($n)

Return 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 β€” so don't go negative and expect coordinates, bestie, you'll get nothing back 😭

Fractional positions give an X,Y position along a straight line between the integer positions. Yes, fractions work. Slay.

  • $n = $path->n_start()

Return 0, the first N in the path. Zero. That's the start. Periodt.

  • ($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)

In the current code the returned range is exact, meaning $n_lo and $n_hi are 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, exact = nice, exact = slow, the trade-off is real πŸ™ˆ

⭐ 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 points in a level, or arms*5^level for multiple arms, numbered starting from 0. Math mathing, as always πŸ’…


🌈 FORMULAS 🌈

πŸ’« X,Y to N πŸ’«

The "xy_to_n()" calculation is similar to the "FlowsnakeCentres". For a given X,Y a modulo 5 remainder is formed:

m = (2*X + Y) mod 5

This distinguishes the five squares making up the base figure. For example in the base N=0 to N=4 part the m values are:

          +-----+
          | m=3 |           1
    +-----+-----+-----+
    | m=0 | m=2 | m=4 |   <- Y=0
    +-----+-----+-----+
          | m=1 |          -1
          +-----+
     X=0     1      2

From this remainder X,Y can be shifted down to the 0 position. That position corresponds to a vector multiple of X=2,Y=1 and 90-degree rotated forms of that vector. That vector can be divided out and X,Y shrunk with:

Xshrunk = (Y + 2*X) / 5
Yshrunk = (2*Y - X) / 5

If X,Y are considered a complex integer X+iY the effect is a remainder modulo 2+i, subtract that to give a multiple of 2+i, then divide by 2+i. The vector X=2,Y=1 or 2+i is because that's the N=5 position after the base shape. The lore checks out πŸ”₯

The remainders can then be mapped to base 5 digits of N going from high to low and making suitable rotations for the sub-part orientation of the curve. The remainders alone give a traversal in the style of "QuintetReplicate". Applying suitable rotations produces the connected path of "QuintetCentres". It's giving build a whole curve out of remainders πŸ’–


πŸ“ OEIS πŸ“

Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include:

<http://oeis.org/A106665> (etc)

A099456   level Y end, being Im((2+i)^k)

arms=2
  A139011   level Y end, being Re((2+i)^k)

πŸŽ€ SEE ALSO πŸŽ€

Math::PlanePath, Math::PlanePath::QuintetCurve, Math::PlanePath::QuintetReplicate, Math::PlanePath::FlowsnakeCentres

(the whole friend group, honestly 🫢)


🌸 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, read the license, for real. it's giving legal, and legal is giving non-negotiable πŸ’€

okay that's the whole page!! this one was perl v5.32.0, dated 2021-01-23, and it was a Math::...Centres(3pm) situation β€” go forth and plot those plus-shaped centre points, you absolute legend πŸ‘‘βœ¨πŸ¦‹