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 can be seen at the
42       following page (quarter way down under "Open Knight's Tour"),
43
44           <http://www.borderschess.org/KTart.htm>
45           <http://www.borderschess.org/KTinfinity.gif>
46           <http://www.borderschess.org/Infinite.gif>
47
48       See math-image to draw the path lines too.
49

FUNCTIONS

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

OEIS

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

SEE ALSO

91       Math::PlanePath, Math::PlanePath::SquareSpiral
92

HOME PAGE

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

LICENSE

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