1Math::PlanePath::HexSpiUrsaelrSkCeownetdr(i3b)uted PerlMDaotchu:m:ePnltaanteiPoanth::HexSpiralSkewed(3)
2
3
4
6 Math::PlanePath::HexSpiralSkewed -- integer points around a skewed
7 hexagonal spiral
8
10 use Math::PlanePath::HexSpiralSkewed;
11 my $path = Math::PlanePath::HexSpiralSkewed->new;
12 my ($x, $y) = $path->n_to_xy (123);
13
15 This path makes a hexagonal spiral with points skewed so as to fit a
16 square grid and fully cover the plane.
17
18 13--12--11 ... 2
19 | \ \
20 14 4---3 10 23 1
21 | | \ \ \
22 15 5 1---2 9 22 <- Y=0
23 \ \ | |
24 16 6---7---8 21 -1
25 \ |
26 17--18--19--20 -2
27
28 ^ ^ ^ ^ ^ ^
29 -2 -1 X=0 1 2 3 ...
30
31 The kinds of N=3*k^2 numbers which fall on straight lines in the plain
32 "HexSpiral" also fall on straight lines when skewed. See
33 Math::PlanePath::HexSpiral for notes on this.
34
35 Skew
36 The skewed path is the same shape as the plain "HexSpiral", but fits
37 more points on a square grid. The skew pushes the top horizontal to
38 the left, as shown by the following parts, and the bottom horizontal is
39 similarly skewed but to the right.
40
41 HexSpiralSkewed HexSpiral
42
43 13--12--11 13--12--11
44 | \ / \
45 14 10 14 10
46 | \ / \
47 15 9 15 9
48
49 -2 -1 X=0 1 2 -4 -3 -2 X=0 2 3 4
50
51 In general the coordinates can be converted each way by
52
53 plain X,Y -> skewed (X-Y)/2, Y
54
55 skewed X,Y -> plain 2*X+Y, Y
56
58 "HexSpiralSkewed" is similar to the "SquareSpiral" but cuts off the
59 top-right and bottom-left corners so that each loop is 6 steps longer
60 than the previous, whereas for the "SquareSpiral" it's 8. See
61 "Corners" in Math::PlanePath::SquareSpiral for other corner cutting.
62
63 Wider
64 An optional "wider" parameter makes the path wider, stretched along the
65 top and bottom horizontals. For example
66
67 $path = Math::PlanePath::HexSpiralSkewed->new (wider => 2);
68
69 gives
70
71 21--20--19--18--17 2
72 | \
73 22 8---7---6---5 16 1
74 | | \ \
75 23 9 1---2---3---4 15 <- Y=0
76 \ \ |
77 24 10--11--12--13--14 ... -1
78 \ |
79 25--26--27--28--29--30 -2
80
81 ^ ^ ^ ^ ^ ^ ^ ^
82 -4 -3 -2 -1 X=0 1 2 3 ...
83
84 The centre horizontal from N=1 is extended by "wider" many further
85 places, then the path loops around that shape. The starting point 1 is
86 shifted to the left by wider/2 places (rounded up to an integer) to
87 keep the spiral centred on the origin X=0,Y=0.
88
89 Each loop is still 6 longer than the previous, since the widening is
90 basically a constant amount added into each loop. The result is the
91 same as the plain "HexSpiral" of the same widening too. The effect
92 looks better in the plain "HexSpiral".
93
94 N Start
95 The default is to number points starting N=1 as shown above. An
96 optional "n_start" can give a different start with the same shape etc.
97 For example to start at 0,
98
99 n_start => 0
100
101 27 26 25 24 3
102 28 12 11 10 23 2
103 29 13 3 2 9 22 1
104 30 14 4 0 1 8 21 ... <- Y=0
105 31 15 5 6 7 20 39 -1
106 32 16 17 18 19 38 -2
107 33 34 35 36 37 -3
108
109 -3 -2 -1 X=0 1 2 3 4
110
111 In this numbering the X axis N=0,1,8,21,etc is the octagonal numbers
112 3*X*(X+1).
113
115 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
116 classes.
117
118 "$path = Math::PlanePath::HexSpiralSkewed->new ()"
119 "$path = Math::PlanePath::HexSpiralSkewed->new (wider => $w)"
120 Create and return a new hexagon spiral object. An optional "wider"
121 parameter widens the spiral path, it defaults to 0 which is no
122 widening.
123
124 "$n = $path->xy_to_n ($x,$y)"
125 Return the point number for coordinates "$x,$y". $x and $y are
126 each rounded to the nearest integer, which has the effect of
127 treating each point in the path as a square of side 1.
128
130 Entries in Sloane's Online Encyclopedia of Integer Sequences related to
131 this path include
132
133 <http://oeis.org/A056105> (etc)
134
135 A056105 N on X axis, 3n^2-2n+1
136 A056106 N on Y axis, 3n^2-n+1
137 A056107 N on North-West diagonal, 3n^2+1
138 A056108 N on X negative axis, 3n^2+n+1
139 A056109 N on Y negative axis, 3n^2+2n+1
140 A003215 N on South-East diagonal, centred hexagonals
141
142 n_start=0
143 A000567 N on X axis, octagonal numbers
144 A049450 N on Y axis
145 A049451 N on X negative axis
146 A045944 N on Y negative axis, octagonal numbers second kind
147 A062783 N on X=Y diagonal north-east
148 A033428 N on north-west diagonal, 3*k^2
149 A063436 N on south-west diagonal
150 A028896 N on south-east diagonal
151
153 Math::PlanePath, Math::PlanePath::HexSpiral,
154 Math::PlanePath::HeptSpiralSkewed, Math::PlanePath::PentSpiralSkewed,
155 Math::PlanePath::DiamondSpiral
156
158 <http://user42.tuxfamily.org/math-planepath/index.html>
159
161 Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
162 2020 Kevin Ryde
163
164 This file is part of Math-PlanePath.
165
166 Math-PlanePath is free software; you can redistribute it and/or modify
167 it under the terms of the GNU General Public License as published by
168 the Free Software Foundation; either version 3, or (at your option) any
169 later version.
170
171 Math-PlanePath is distributed in the hope that it will be useful, but
172 WITHOUT ANY WARRANTY; without even the implied warranty of
173 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
174 General Public License for more details.
175
176 You should have received a copy of the GNU General Public License along
177 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
178
179
180
181perl v5.32.1 2021-01-27Math::PlanePath::HexSpiralSkewed(3)