Math::...areArms(3pm)
πΈ 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$non the path. For"$n < 1"the return is an empty list, as the path starts at1. (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()"β Return4. 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 adloforNloand the corners forNhi, 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::PlanePathMath::PlanePath::DiamondArmsMath::PlanePath::HexArmsMath::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!!
π¦ 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