1Math::PlanePath::HeptSpUisrearlSCkoenwterdi(b3u)ted PerlMaDtohc:u:mPelnatnaetPiaotnh::HeptSpiralSkewed(3)
2
3
4
6 Math::PlanePath::HeptSpiralSkewed -- integer points around a skewed
7 seven sided spiral
8
10 use Math::PlanePath::HeptSpiralSkewed;
11 my $path = Math::PlanePath::HeptSpiralSkewed->new;
12 my ($x, $y) = $path->n_to_xy (123);
13
15 This path makes a seven-sided spiral by cutting one corner of a square
16
17 31-30-29-28 3
18 | \
19 32 14-13-12 27 2
20 | | \ \
21 33 15 4--3 11 26 1
22 | | | \ \ \
23 34 16 5 1--2 10 25 <- Y=0
24 | | | | |
25 35 17 6--7--8--9 24 -1
26 | | |
27 36 18-19-20-21-22-23 -2
28 |
29 37-38-39-40-41-... -3
30
31 ^
32 -3 -2 -1 X=0 1 2 3
33
34 The path is as if around a heptagon, with the left and bottom here as
35 two sides of the heptagon straightened out, and the flat top here
36 skewed across to fit a square grid.
37
38 N Start
39 The default is to number points starting N=1 as shown above. An
40 optional "n_start" can give a different start, in the same pattern.
41 For example to start at 0,
42
43 30 29 28 27 n_start => 0
44 31 13 12 11 26
45 32 14 3 2 10 25
46 33 15 4 0 1 9 24
47 34 16 5 6 7 8 23
48 35 17 18 19 20 21 22
49 36 37 38 39 40 ...
50
52 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
53 classes.
54
55 "$path = Math::PlanePath::HeptSpiralSkewed->new ()"
56 "$path = Math::PlanePath::HeptSpiralSkewed->new (n_start => $n)"
57 Create and return a new path object.
58
59 "$n = $path->xy_to_n ($x,$y)"
60 Return the point number for coordinates "$x,$y". $x and $y are
61 each rounded to the nearest integer, which has the effect of
62 treating each N in the path as centred in a square of side 1, so
63 the entire plane is covered.
64
66 N to X,Y
67 It's convenient to work in terms of Nstart=0 and to take each loop as
68 beginning on the South-West diagonal,
69
70 top length = d
71
72 30-29-28-27
73 | \
74 31 26 diagonal length = d
75 left | \
76 length 32 25
77 = 2*d | \
78 33 0 24
79 | | right
80 34 . 23 length = d-1
81 | |
82 35 17-18-19-20-21-22
83 |
84 . bottom length = 2*d-1
85
86 The SW diagonal is N=0,5,17,36,etc which is
87
88 N = (7d-11)*d/2 + 2 # starting d=1 first loop
89
90 This can be inverted to get d from N
91
92 d = floor( (sqrt(56*N+9)+11)/14 )
93
94 The side lengths are as shown above. The first loop is d=1 and for it
95 the "right" vertical length is zero, so no such side on that first loop
96 0 <= N < 5.
97
99 Entries in Sloane's Online Encyclopedia of Integer Sequences related to
100 this path include
101
102 <http://oeis.org/A192136> (etc)
103
104 n_start=1
105 A140065 N on Y axis
106
107 n_start=0
108 A001106 N on X axis, 9-gonal numbers
109 A218471 N on Y axis
110 A022265 N on X negative axis
111 A179986 N on Y negative axis, second 9-gonals
112 A195023 N on X=Y diagonal
113 A022264 N on North-West diagonal
114 A186029 N on South-West diagonal
115 A024966 N on South-East diagonal
116
118 Math::PlanePath, Math::PlanePath::SquareSpiral,
119 Math::PlanePath::PentSpiralSkewed, Math::PlanePath::HexSpiralSkewed
120
122 <http://user42.tuxfamily.org/math-planepath/index.html>
123
125 Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
126 2020 Kevin Ryde
127
128 This file is part of Math-PlanePath.
129
130 Math-PlanePath is free software; you can redistribute it and/or modify
131 it under the terms of the GNU General Public License as published by
132 the Free Software Foundation; either version 3, or (at your option) any
133 later version.
134
135 Math-PlanePath is distributed in the hope that it will be useful, but
136 WITHOUT ANY WARRANTY; without even the implied warranty of
137 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
138 General Public License for more details.
139
140 You should have received a copy of the GNU General Public License along
141 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
142
143
144
145perl v5.34.0 2022-01-2M1ath::PlanePath::HeptSpiralSkewed(3)