Math::...areArms(3pm)

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

🌸 Math::PlanePath::SquareArms πŸ’…

ok so bestie, this is a page from the User Contributed Perl Documentation collection, and it's about Math::PlanePath::SquareArms β€” yes the name is a whole mouthful, we're calling it SquareArms from here on, no cap. It lives in the Math::PlanePath family and it draws four spiral arms. Buckle up, it's giving geometry girlboss energy. ✨


✨ NAME ✨

Math::PlanePath::SquareArms β€” four spiral arms πŸŒ€πŸŒ€πŸŒ€πŸŒ€


✨ SYNOPSIS ✨

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

✨ DESCRIPTION ✨

This path follows four spiral arms, each one advancing successively, and honestly the way they weave is lowkey mesmerizing:

                ...--33--29                 3
                          |
     26--22--18--14--10  25                 2
      |               |   |
     30  11-- 7-- 3   6  21                 1
      |   |           |   |
    ...  15   4   1   2  17  ...        <- Y=0
          |   |   |       |   |
         19   8   5-- 9--13  32            -1
          |   |               |
         23  12--16--20--24--28            -2
          |
         27--31--...                       -3

      ^   ^   ^   ^   ^   ^   ^
     -3  -2  -1  X=0  1   2   3 ...

Each arm is quadratic, with each loop 128 longer than the preceding one. And the perfect squares? Obsessed. They fall in eight straight lines, 4 with the even squares on the X and Y axes and the odd squares on the diagonals X=Y and X=-Y. Iconic behavior honestly.

Some novel straight lines arise from numbers which are a repdigit in one or more bases (Sloane's A167782). "111" in various bases falls on straight lines. Numbers "[16][16][16]" in bases 17,19,21,etc are a horizontal at Y=3 because they're perfect squares, and "[64][64][64]" in base 65,66,etc go a vertically downwards from X=12,Y=-266 similarly because they're squares. like,, the squares really said "we're going places" πŸ’€

Each arm is N=4*k+rem for a remainder rem=0,1,2,3, so sequences related to multiples of 4 or with a modulo 4 pattern may fall on particular arms. iykyk. πŸŽ€


✨ FUNCTIONS ✨

See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. (the shared lore, bestie πŸ’–)

  • "$path = Math::PlanePath::SquareArms->new ()" β€” Create and return a new path object. slay, you have a path now. 🫢
  • "($x,$y) = $path->n_to_xy ($n)" β€” Return the X,Y coordinates of point number $n on the path. For "$n < 1" the return is an empty list, as the path starts at 1. (it starts at 1 bestie, not 0, we don't do 0 here πŸ’…)

Fractional $n gives a point on the line between $n and "$n+4", that "$n+4" being the next point on the same spiralling arm. This is probably of limited use, but arises fairly naturally from the calculation. (it's giving "we didn't plan this but here we are" 🌸)

Descriptive Methods πŸ¦‹

  • "$arms = $path->arms_count()" β€” Return 4. that's it. that's the whole function. four arms, four ever, periodt. ✨

✨ FORMULAS ✨

Rectangle N Range πŸ“

Within a square X=-d...+d, and Y=-d...+d the biggest N is the end of the N=5 arm in that square, which is N=9, 25, 49, 81, etc, (2d+1)^2, in successive corners of the square. So for a rectangle find a surrounding d square,

d = max(abs(x1),abs(y1),abs(x2),abs(y2))

from which

Nmax = (2*d+1)^2
     = (4*d + 4)*d + 1

This can be used for a minimum too by finding the smallest d covered by the rectangle.

dlo = max (0,
           min(abs(y1),abs(y2)) if x=0 not covered
           min(abs(x1),abs(x2)) if y=0 not covered
          )

from which the maximum of the preceding dlo-1 square,

Nlo = /  1 if dlo=0
      \  (2*(dlo-1)+1)^2 +1  if dlo!=0
          = (2*dlo - 1)^2
          = (4*dlo - 4)*dlo + 1

For a tighter maximum, horizontally N increases to the left or right of the diagonal X=Y line (or X=Y+/-1 line), which means one end or the other is the maximum. Similar vertically N increases above or below the off-diagonal X=-Y so the top or bottom is the maximum. This means for a rectangle the biggest N is at one of the four corners,

Nhi = max (xy_to_n (x1,y1),
           xy_to_n (x1,y2),
           xy_to_n (x2,y1),
           xy_to_n (x2,y2))
The current code uses a dlo for Nlo and the corners for Nhi, which means the high is exact but the low is not. (the high ate and left no crumbs; the low is approximate, and we're honest about it πŸ™ˆ)

✨ SEE ALSO ✨

  • Math::PlanePath
  • Math::PlanePath::DiamondArms
  • Math::PlanePath::HexArms
  • Math::PlanePath::SquareSpiral

(the whole friend group πŸ’œ)


✨ HOME PAGE ✨

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

go click it bestie, the URL is right there 🌈


✨ 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 this is legal text so no jokes, but fr fr: the no-warranty part is real and it matters. read it. πŸ’€

and that's the whole page!! 🌟 this one's from perl v5.32.0, dated 2021-01-23, and it's page Math::...areArms(3pm) in the User Contributed Perl Documentation set. you read the entire thing, main character energy, so proud of you πŸ«ΆπŸ’–βœ¨ bye bestie!!