1Math::PlanePath::KnightUSspeirraClo(n3t)ributed Perl DocMuamtehn:t:aPtliaonnePath::KnightSpiral(3)
2
3
4

NAME

6       Math::PlanePath::KnightSpiral -- integer points around a square, by
7       chess knight moves
8

SYNOPSIS

10        use Math::PlanePath::KnightSpiral;
11        my $path = Math::PlanePath::KnightSpiral->new;
12        my ($x, $y) = $path->n_to_xy (123);
13

DESCRIPTION

15       This path traverses the plane by an infinite "knight's tour" in the
16       form of a square spiral.
17
18                                   ...
19               21   4   9  14  19                 2
20
21               10  15  20   3   8      28         1
22
23                5  22   1  18  13            <- Y=0
24
25               16  11  24   7   2  27             1
26
27               23   6  17  12  25                 2
28
29                                       26
30
31                        ^
32               -2  -1  X=0  1   2   3
33
34       Each step is a chess knight's move 1 across and 2 along, or vice versa.
35       The pattern makes 4 cycles on a 2-wide path around a square before
36       stepping outwards to do the same again to a now bigger square.  The
37       above sample shows the first 4-cycle around the central 1, then
38       stepping out at 26 and beginning to go around the outside of the 5x5
39       square.
40
41       An attractive traced out picture of the path appeared in the past at
42       "www.borderschess.org",
43
44           <http://web.archive.org/web/1id_/http://www.borderschess.org/Infinite.gif>
45
46           <http://web.archive.org/web/1id_/http://www.borderschess.org/KTinfinity.gif>
47
48           <http://web.archive.org/web/20161028114643id_/http://www.borderschess.org/KTart.htm>
49
50       (HTML colours might might make the text invisible.  Try deleting, or
51       browser option to ignore page colours, or a text browser.)
52
53       See math-image to draw the path lines too.
54

FUNCTIONS

56       See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
57       classes.
58
59       "$path = Math::PlanePath::KnightSpiral->new ()"
60           Create and return a new knight spiral object.
61
62       "($x,$y) = $path->n_to_xy ($n)"
63           Return the X,Y coordinates of point number $n on the path.
64
65           For "$n < 1" the return is an empty list, it being considered the
66           path starts at 1.
67
68       "$n = $path->xy_to_n ($x,$y)"
69           Return the point number for coordinates "$x,$y".  $x and $y are
70           each rounded to the nearest integer, which has the effect of
71           treating each N in the path as centred in a square of side 1, so
72           the entire plane is covered.
73

OEIS

75       This Knight's tour is in Sloane's OEIS following the Knight spiral and
76       giving the resulting X,Y location by the "SquareSpiral" numbering.
77       There's eight forms for 4 rotations and the two spirals same or
78       opposite directions.
79
80           <http://oeis.org/A068608> (etc)
81
82           permutations
83             A068608   same knight and square spiral directions
84             A068609   rotate 90 degrees
85             A068610   rotate 180 degrees
86             A068611   rotate 270 degrees
87             A068612   rotate 180 degrees, spiral opp dir (X negate)
88             A068613   rotate 270 degrees, spiral opp dir
89             A068614   spiral opposite direction (Y negate)
90             A068615   rotate 90 degrees, spiral opp dir (X,Y transpose)
91
92       See examples/knights-oeis.pl for a sample program printing the values
93       of A068608.
94

SEE ALSO

96       Math::PlanePath, Math::PlanePath::SquareSpiral
97

HOME PAGE

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

LICENSE

102       Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
103       2020 Kevin Ryde
104
105       This file is part of Math-PlanePath.
106
107       Math-PlanePath is free software; you can redistribute it and/or modify
108       it under the terms of the GNU General Public License as published by
109       the Free Software Foundation; either version 3, or (at your option) any
110       later version.
111
112       Math-PlanePath is distributed in the hope that it will be useful, but
113       WITHOUT ANY WARRANTY; without even the implied warranty of
114       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
115       General Public License for more details.
116
117       You should have received a copy of the GNU General Public License along
118       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
119
120
121
122perl v5.34.0                      2021-07-22  Math::PlanePath::KnightSpiral(3)
Impressum