Math::...tSpiral(3pm)
πΈ Math::PlanePath::KnightSpiral β the manpage bestie π
okay so this is a Perl manpage from the User Contributed Perl Documentation collection, and it's about Math::PlanePath::KnightSpiral. yes the header truncates it to Math::...tSpiral(3pm) because someone did NOT give it enough room to breathe, but we know what it is. π
β¨ NAME β¨
Math::PlanePath::KnightSpiral β integer points around a square, by chess knight moves π΄
β¨ SYNOPSIS β¨
use Math::PlanePath::KnightSpiral;
my $path = Math::PlanePath::KnightSpiral->new;
my ($x, $y) = $path->n_to_xy (123);
β¨ DESCRIPTION β¨
so this path traverses the plane by an infinite "knight's tour" shaped like a square spiral. iconic behaviour honestly.
...
21 4 9 14 19 2
10 15 20 3 8 28 1
5 22 1 18 13 <- Y=0
16 11 24 7 2 27 1
23 6 17 12 25 2
26
^
-2 -1 X=0 1 2 3
every single step is a chess knight's move β 1 across and 2 along, or vice versa. the pattern does 4 cycles on a 2-wide path around a square before it steps outwards and does the whole thing again on a now-bigger square. the sample up there shows the first 4-cycle around the central 1, then it steps out at 26 and starts going around the outside of the 5x5 square. she's expanding. she's growing. main character energy fr fr. π
an attractive traced out picture of the path appeared in the past at "www.borderschess.org", and the links are these:
<http://web.archive.org/web/1id_/http://www.borderschess.org/Infinite.gif><http://web.archive.org/web/1id_/http://www.borderschess.org/KTinfinity.gif><http://web.archive.org/web/20161028114643id_/http://www.borderschess.org/KTart.htm>
π heads up bestie β HTML colours might might make the text invisible. try deleting, or browser option to ignore page colours, or a text browser.
also, see math-image to draw the path lines too. π
β¨ FUNCTIONS β¨
see "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. that's the shared lore, iykyk.
π«Ά "$path = Math::PlanePath::KnightSpiral->new ()"
create and return a new knight spiral object. brand new baby spiral, no cap.
π«Ά "($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, it being considered the path starts at 1. so like, nothing before 1. the path simply does not exist there. periodt.
π«Ά "$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 N in the path as centred in a square of side 1, so the entire plane is covered. every last bit of it. slay.
β¨ OEIS β¨
this Knight's tour is in Sloane's OEIS following the Knight spiral and giving the resulting X,Y location by the "SquareSpiral" numbering. there's eight forms for 4 rotations and the two spirals same or opposite directions. eight whole flavours. π
<http://oeis.org/A068608>(etc)
permutations:
A068608 same knight and square spiral directions
A068609 rotate 90 degrees
A068610 rotate 180 degrees
A068611 rotate 270 degrees
A068612 rotate 180 degrees, spiral opp dir (X negate)
A068613 rotate 270 degrees, spiral opp dir
A068614 spiral opposite direction (Y negate)
A068615 rotate 90 degrees, spiral opp dir (X,Y transpose)
see examples/knights-oeis.pl for a sample program printing the values of A068608. go run it bestie, it's cute. β¨
β¨ SEE ALSO β¨
Math::PlanePathMath::PlanePath::SquareSpiral
β¨ HOME PAGE β¨
β¨ 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/>.
π and that's the whole page!! this beauty is perl v5.32.0, dated 2021-01-23, and it lives under the Math::...tSpiral(3pm) name in the User Contributed Perl Documentation. mwah. go spiral around a square like a knight, you've got this. πβ¨π¦
π¦ 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