1Math::PlanePath::PentSpUisrearl(C3o)ntributed Perl DocumMeanttha:t:iPolnanePath::PentSpiral(3)
2
3
4
6 Math::PlanePath::PentSpiral -- integer points in a pentagonal shape
7
9 use Math::PlanePath::PentSpiral;
10 my $path = Math::PlanePath::PentSpiral->new;
11 my ($x, $y) = $path->n_to_xy (123);
12
14 This path makes a pentagonal (five-sided) spiral with points spread out
15 to fit on a square grid.
16
17 22 3
18
19 23 10 21 2
20
21 24 11 3 9 20 1
22
23 25 12 4 1 2 8 19 <- Y=0
24
25 26 13 5 6 7 18 ... -1
26
27 27 14 15 16 17 33 -2
28
29 28 29 30 31 32 -2
30
31
32 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
33 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7
34
35 Each horizontal gap is 2, so for instance n=1 is at x=0,y=0 then n=2 is
36 at x=2,y=0. The lower diagonals are 1 across and 1 down, so n=17 is at
37 x=4,y=-2 and n=18 is x=5,y=-1. But the upper angles go 2 across and 1
38 up, so n=20 is x=4,y=1 then n=21 is x=2,y=2.
39
40 The effect is to make the sides equal length, except for a kink at the
41 lower right corner. Only every second square in the plane is used. In
42 the top half (y>=0) those points line up, in the lower half (y<0)
43 they're offset on alternate rows.
44
45 N Start
46 The default is to number points starting N=1 as shown above. An
47 optional "n_start" can give a different start, in the same pattern.
48 For example to start at 0,
49
50 n_start => 0 38
51
52 39 21 37
53 ...
54 40 22 9 20 36 57
55
56 41 23 10 2 8 19 35 56
57
58 42 24 11 3 0 1 7 18 34 55
59
60 43 25 12 4 5 6 17 33 54
61
62 44 26 13 14 15 16 32 53
63
64 45 27 28 29 30 31 52
65
66 46 47 48 49 50 51
67
69 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
70 classes.
71
72 "$path = Math::PlanePath::PentSpiral->new ()"
73 "$path = Math::PlanePath::PentSpiral->new (n_start => $n)"
74 Create and return a new pentagon spiral object.
75
76 "$n = $path->xy_to_n ($x,$y)"
77 Return the point number for coordinates "$x,$y". $x and $y are
78 each rounded to the nearest integer, which has the effect of
79 treating each point in the path as a square of side 1.
80
82 N to X,Y
83 It's convenient to work in terms of Nstart=0 and to take each loop as
84 beginning on the South-West diagonal,
85
86 21 loop d=3
87 -- --
88 22 20
89 -- --
90 23 19
91 -- --
92 24 0 18
93 \ /
94 25 . 17
95 \ /
96 26 13----14----15----16
97 \
98 .
99
100 The SW diagonal is N=0,4,13,27,46,etc which is
101
102 N = (5d-7)*d/2 + 1 # starting d=1 first loop
103
104 This can be inverted to get d from N
105
106 d = floor( (sqrt(40*N + 9) + 7) / 10 )
107
108 Each side is length d, except the lower right diagonal slope which is
109 d-1. For the very first loop that lower right is length 0.
110
112 Entries in Sloane's Online Encyclopedia of Integer Sequences related to
113 this path include
114
115 <http://oeis.org/A140066> (etc)
116
117 n_start=1 (the default)
118 A192136 N on X axis, (5*n^2 - 3*n + 2)/2
119 A140066 N on Y axis
120 A116668 N on X negative axis
121 A005891 N on South-East diagonal, centred pentagonals
122 A134238 N on South-West diagonal
123
124 n_start=0
125 A000566 N on X axis, heptagonal numbers
126 A005476 N on Y axis
127 A028895 N on South-East diagonal
128
130 Math::PlanePath, Math::PlanePath::PentSpiralSkewed,
131 Math::PlanePath::HexSpiral
132
134 <http://user42.tuxfamily.org/math-planepath/index.html>
135
137 Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
138 2020 Kevin Ryde
139
140 This file is part of Math-PlanePath.
141
142 Math-PlanePath is free software; you can redistribute it and/or modify
143 it under the terms of the GNU General Public License as published by
144 the Free Software Foundation; either version 3, or (at your option) any
145 later version.
146
147 Math-PlanePath is distributed in the hope that it will be useful, but
148 WITHOUT ANY WARRANTY; without even the implied warranty of
149 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
150 General Public License for more details.
151
152 You should have received a copy of the GNU General Public License along
153 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
154
155
156
157perl v5.36.0 2022-07-22 Math::PlanePath::PentSpiral(3)