Math::...tSpiral(3pm)

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

πŸ’– NAME πŸ’–

Math::PlanePath::PentSpiral β€” bestie, it's integer points arranged in a pentagonal shape. Five sides, all the vibes. ✨

(It's the Perl module Math::PlanePath::PentSpiral, from the User Contributed Perl Documentation, section 3pm. Yes, the title got cut off in the header, we don't talk about it. πŸ’…)


πŸ¦‹ SYNOPSIS πŸ¦‹

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

That's it. That's the whole entrance. Slay. πŸ’…


✨ DESCRIPTION ✨

Okay so this path makes a pentagonal (five-sided) spiral, and the points are spread out to fit on a square grid. It's giving geometry but make it grid-compatible. 🌸

                      22                              3

                23    10    21                        2

          24    11     3     9    20                  1

    25    12     4     1     2     8    19       <- Y=0

       26    13     5     6     7    18    ...       -1

          27    14    15    16    17    33           -2

             28    29    30    31    32              -2

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

So the way this works: every horizontal gap is 2. Like, for instance n=1 sits at x=0,y=0 and then n=2 is at x=2,y=0. No cap. 🫢

The lower diagonals are 1 across and 1 down β€” so n=17 is at x=4,y=-2 and n=18 is x=5,y=-1. But the upper angles go 2 across and 1 up, so n=20 is x=4,y=1 and then n=21 is x=2,y=2. Different energy for different corners, honestly iconic. πŸ‘‘

The effect is to make the sides equal length, except for a little kink at the lower right corner (we love her anyway). Only every second square in the plane is used. In the top half (y>=0) those points line up all neat, and in the lower half (y<0) they're offset on alternate rows. Chaos but make it aesthetic. 🌈

πŸŽ€ N Start πŸŽ€

The default is to number points starting N=1 as shown up above. An optional "n_start" can give a different start, in the same pattern. Like, for example, to start at 0:

    n_start => 0            38

                      39    21    37
                                           ...
                40    22     9    20    36    57

          41    23    10     2     8    19    35    56

    42    24    11     3     0     1     7    18    34    55

       43    25    12     4     5     6    17    33    54

          44    26    13    14    15    16    32    53

             45    27    28    29    30    31    52

                46    47    48    49    50    51

Same spiral, different starting number. The pattern stays exactly the same, we just shifted the vibe. ✨


🫢 FUNCTIONS 🫢

See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. Yes, that's the shared lore, go read it, iykyk. πŸ’œ

  • $path = Math::PlanePath::PentSpiral->new ()
  • $path = Math::PlanePath::PentSpiral->new (n_start => $n)

Create and return a new pentagon spiral object. Fresh out the box, ready to spiral. πŸŒ€

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

Return the point number for coordinates "$x,$y". $x and $y are each rounded to the nearest integer, which has the effect of treating each point in the path as a square of side 1. So it's forgiving about your decimals, bestie. πŸ’…


⭐ FORMULAS ⭐

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

It's convenient to work in terms of Nstart=0 and to take each loop as beginning on the South-West diagonal, like:

                      21                loop d=3
                   --    --
                22          20
             --                --
          23                      19
       --                            --
    24                 0                18
      \                                /
       25          .                 17
         \                          /
          26    13----14----15----16
            \
             .

The SW diagonal is N=0,4,13,27,46,etc which is

N = (5d-7)*d/2 + 1           # starting d=1 first loop

This can be inverted to get d from N:

d = floor( (sqrt(40*N + 9) + 7) / 10 )

Each side is length d, except the lower right diagonal slope which is d-1. For the very first loop that lower right is length 0. Special case, don't come for her. πŸ™ˆ


🌸 OEIS 🌸

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

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

n_start=1 (the default)
  A192136    N on X axis, (5*n^2 - 3*n + 2)/2
  A140066    N on Y axis
  A116668    N on X negative axis
  A005891    N on South-East diagonal, centred pentagonals
  A134238    N on South-West diagonal

n_start=0
  A000566    N on X axis, heptagonal numbers
  A005476    N on Y axis
  A028895    N on South-East diagonal

Go look them up, they're lowkey addictive. πŸ”₯


🧚 SEE ALSO 🧚

  • Math::PlanePath
  • Math::PlanePath::PentSpiralSkewed
  • Math::PlanePath::HexSpiral

🌈 HOME PAGE 🌈

<http://user42.tuxfamily.org/math-planepath/index.html>


πŸ‘‘ LICENSE πŸ‘‘

Copyright 2010, 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 read the license, bestie, it's not a vibe to skip it. 🫢

And that's the whole page, periodt. πŸ’… This was perl v5.32.0, dated 2021-01-23, straight out of the Math::...tSpiral(3pm) files. Go spiral something pentagonal, you got this. πŸŽ€βœ¨πŸ¦‹