1Math::PlanePath::TriangUuslearrHCyopnottr(i3b)uted PerlMDaotchu:m:ePnltaanteiPoanth::TriangularHypot(3)
2
3
4

NAME

6       Math::PlanePath::TriangularHypot -- points of triangular lattice in
7       order of hypotenuse distance
8

SYNOPSIS

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

DESCRIPTION

15       This path visits X,Y points on a triangular "A2" lattice in order of
16       their distance from the origin 0,0 and anti-clockwise around from the X
17       axis among those of equal distance.
18
19                    58    47    39    46    57                 4
20
21                 48    34    23    22    33    45              3
22
23              40    24    16     9    15    21    38           2
24
25           49    25    10     4     3     8    20    44        1
26
27              35    17     5     1     2    14    32      <- Y=0
28
29           50    26    11     6     7    13    31    55       -1
30
31              41    27    18    12    19    30    43          -2
32
33                 51    36    28    29    37    54             -3
34
35                    60    52    42    53    61                -4
36
37                                 ^
38           -7 -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7
39
40       The lattice is put on a square X,Y grid using every second point per
41       "Triangular Lattice" in Math::PlanePath.  Scaling X/2,Y*sqrt(3)/2 gives
42       equilateral triangles of side length 1 making a distance from X,Y to
43       the origin
44
45           dist^2 = (X/2^2 + (Y*sqrt(3)/2)^2
46                  = (X^2 + 3*Y^2) / 4
47
48       For example N=19 at X=2,Y=-2 is sqrt((2**2+3*-2**2)/4) = sqrt(4) from
49       the origin.  The next smallest after that is X=5,Y=1 at sqrt(7).  The
50       key part is X^2 + 3*Y^2 as the distance measure to order the points.
51
52   Equal Distances
53       Points with the same distance are taken in anti-clockwise order around
54       from the X axis.  For example N=14 at X=4,Y=0 is sqrt(4) from the
55       origin, and so are the rotated X=2,Y=2 and X=-2,Y=2 etc in other sixth
56       segments, for a total 6 points N=14 to N=19 all the same distance.
57
58       Symmetry means there's a set of 6 or 12 points with the same distance,
59       so the count of same-distance points is always a multiple of 6 or 12.
60       There are 6 symmetric points when on the six radial lines X=0, X=Y or
61       X=-Y, and on the lines Y=0, X=3*Y or X=-3*Y which are midway between
62       them.  There's 12 symmetric points for anything else, ie. anything in
63       the twelve slices between those twelve lines.  The first set of 12
64       equal is N=20 to N=31 all at sqrt(28).
65
66       There can also be further ways for the same distance to arise, as
67       multiple solutions to X^2+3*Y^3=d^2, but the 6-way or 12-way symmetry
68       means there's always a multiple of 6 or 12 in total.
69
70   Odd Points
71       Option "points => "odd"" visits just the odd points, meaning sum X+Y
72       odd, which is X,Y one odd the other even.
73
74           points => "odd"
75                                69                              5
76                 66    50    45    44    49    65               4
77              58    40    28    25    27    39    57            3
78           54    32    20    12    11    19    31    53         2
79              36    16     6     3     5    15    35            1
80           46    24    10     2     1     9    23    43    <- Y=0
81              37    17     7     4     8    18    38           -1
82           55    33    21    13    14    22    34    56        -2
83              59    41    29    26    30    42    60           -3
84                 67    51    47    48    52    68              -4
85                                70                             -5
86
87                                 ^
88              -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6
89
90   All Points
91       Option "points => "all"" visits all integer X,Y points.
92
93           points => "all"
94
95                       64 59 49 44 48 58 63                  3
96                 69 50 39 30 25 19 24 29 38 47 68            2
97                 51 35 20 13  8  4  7 12 18 34 46            1
98              65 43 31 17  9  3  1  2  6 16 28 42 62    <- Y=0
99                 52 36 21 14 10  5 11 15 23 37 57           -1
100                 70 53 40 32 26 22 27 33 41 56 71           -2
101                       66 60 54 45 55 61 67                 -3
102
103                                 ^
104              -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6
105
106   Hex Points
107       Option "points => "hex"" visits X,Y points making a hexagonal grid,
108
109           points => "hex"
110
111                                50----42          49----59                    5
112                               /        \        /        \
113                       51----39          27----33          48                 4
114                      /        \        /        \        /
115                    43          22----15          21----32                    3
116                      \        /        \        /        \
117                       28----16           6----11          26----41           2
118                      /        \        /        \        /        \
119              52----34           7---- 3           5----14          47        1
120             /        \        /        \        /        \        /
121           60          23----12           1-----2          20----38      <- Y=0
122             \        /        \        /        \        /        \
123              53----35           8---- 4          10----19          58       -1
124                      \        /        \        /        \        /
125                       29----17           9----13          31----46          -2
126                      /        \        /        \        /
127                    44          24----18          25----37                   -3
128                      \        /        \        /        \
129                       54----40          30----36          57                -4
130                               \        /        \        /
131                                55----45          56----61                   -5
132
133                                          ^
134              -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7  8  9
135
136       N=1 is at the origin X=0,Y=0, then N=2,3,4 are all at X^2+3Y^2=4 away
137       from the origin, etc.  The joining lines drawn above show the grid
138       pattern but points are in order of distance from the origin.
139
140       The points are all integer X,Y with X+3Y mod 6 == 0 or 2.  This is a
141       subset of the default "even" points in that X+Y is even but with 1 of
142       each 3 points skipped to make the hexagonal outline.
143
144   Hex Rotated Points
145       Option "points => "hex_rotated"" is the same hexagonal points but
146       rotated around so N=2 is at +60 degrees instead of on the X axis.
147
148           points => "hex_rotated"
149
150
151                       60----50          42----49                             5
152                      /        \        /        \
153                    51          33----27          38----48                    4
154                      \        /        \        /        \
155                       34----22          15----21          41                 3
156                      /        \        /        \        /
157              43----28          12-----6          14----26                    2
158             /        \        /        \        /        \
159           52          16-----7           2-----5          32----47           1
160             \        /        \        /        \        /        \
161              39----23           3-----1          11----20          59   <- Y=0
162             /        \        /        \        /        \        /
163           53          17-----8           4----10          37----58          -1
164             \        /        \        /        \        /
165              44----29          13-----9          19----31                   -2
166                      \        /        \        /        \
167                       35----24          18----25          46                -3
168                      /        \        /        \        /
169                    54          36----30          40----57                   -4
170                      \        /        \        /
171                       61----55          45----56                            -5
172
173
174                                       ^
175           -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7  8  9
176
177       Points are still numbered from the X axis clockwise.  The sets of
178       points at equal hypotenuse distances are the same as plain "hex" but
179       the numbering is changed by the rotation.
180
181       The points visited are all integer X,Y with X+3Y mod 6 == 0 or 4.  This
182       grid can be viewed either as a +60 degree or a +180 degree rotation of
183       the plain hex.
184
185   Hex Centred Points
186       Option "points => "hex_centred"" is the same hexagonal grid as hex
187       above, but with the origin X=0,Y=0 in the centre of a hexagon,
188
189           points => "hex_centred"
190
191                                46----45                              5
192                               /        \
193                       39----28          27----38                     4
194                      /        \        /        \
195              47----29          16----15          26----44            3
196             /        \        /        \        /        \
197           48          17-----9           8----14          43         2
198             \        /        \        /        \        /
199              30----18           3-----2          13----25            1
200             /        \        /        \        /        \
201           40          10-----4     .     1-----7          37    <- Y=0
202             \        /        \        /        \        /
203              31----19           5-----6          24----36           -1
204             /        \        /        \        /        \
205           49          20----11          12----23          54        -2
206             \        /        \        /        \        /
207              50----32          21----22          35----53           -3
208                      \        /        \        /
209                       41----33          34----42                    -4
210                               \        /
211                                51----52                             -5
212
213                                    ^
214           -8 -7 -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7  8  9
215
216       N=1,2,3,4,5,6 are all at X^2+3Y^2=4 away from the origin, then
217       N=7,8,9,10,11,12, etc.  The points visited are all integer X,Y with
218       X+3Y mod 6 == 2 or 4.
219

FUNCTIONS

221       See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
222       classes.
223
224       "$path = Math::PlanePath::TriangularHypot->new ()"
225       "$path = Math::PlanePath::TriangularHypot->new (points => $str)"
226           Create and return a new hypot path object.  The "points" option can
227           be
228
229               "even"          only points with X+Y even (the default)
230               "odd"           only points with X+Y odd
231               "all"           all integer X,Y
232               "hex"           hexagonal X+3Y==0,2 mod 6
233               "hex_rotated"   hexagonal X+3Y==0,4 mod 6
234               "hex_centred"   hexagonal X+3Y==2,4 mod 6
235
236           Create and return a new triangular hypot path object.
237
238       "($x,$y) = $path->n_to_xy ($n)"
239           Return the X,Y coordinates of point number $n on the path.
240
241           For "$n < 1" the return is an empty list as the first point at
242           X=0,Y=0 is N=1.
243
244           Currently it's unspecified what happens if $n is not an integer.
245           Successive points are a fair way apart, so it may not make much
246           sense to say give an X,Y position in between the integer $n.
247
248       "$n = $path->xy_to_n ($x,$y)"
249           Return an integer point number for coordinates "$x,$y".  Each
250           integer N is considered the centre of a unit square and an "$x,$y"
251           within that square returns N.
252
253           For "even" and "odd" options only every second square in the plane
254           has an N and if "$x,$y" is a position not covered then the return
255           is "undef".
256

OEIS

258       Entries in Sloane's Online Encyclopedia of Integer Sequences related to
259       this path include,
260
261           <http://oeis.org/A003136> (etc)
262
263           points="even" (the default)
264             A003136  norms (X^2+3*Y^2)/4 which occur
265             A004016  count of points of norm==n
266             A035019    skipping zero counts
267             A088534    counting only in the twelfth 0<=X<=Y
268
269       The counts in these sequences are expressed as norm = x^2+x*y+y^2.
270       That x,y is related to the "even" X,Y on the path here by a -45 degree
271       rotation,
272
273           x = (Y-X)/2           X = 2*(x+y)
274           y = (X+Y)/2           Y = 2*(y-x)
275
276           norm = x^2+x*y+y^2
277                = ((Y-X)/2)^2 + (Y-X)/2 * (X+Y)/2 + ((X+Y)/2)^2
278                = (X^2 + 3*Y^2) / 4
279
280       The X^2+3*Y^2 is the dist^2 described above for equilateral triangles
281       of unit side.  The factor of /4 scales the distance but of course
282       doesn't change the sets of points of the same distance.
283
284           points="all"
285             A092572  norms X^2+3*Y^2 which occur
286             A158937  norms X^2+3*Y^2 which occur, X>0,Y>0 with repeats
287             A092573  count of points norm==n for X>0,Y>0
288
289             A092574  norms X^2+3*Y^2 which occur for X>0,Y>0, gcd(X,Y)=1
290             A092575  count of points norm==n for X>0,Y>0, gcd(X,Y)=1
291                        ie. X,Y no common factor
292
293           points="hex"
294             A113062  count of points norm=X^2+3*Y^2=4*n (theta series)
295             A113063   divided by 3
296
297           points="hex_centred"
298             A217219  count of points norm=X^2+3*Y^2=4*n (theta series)
299

SEE ALSO

301       Math::PlanePath, Math::PlanePath::Hypot, Math::PlanePath::HypotOctant,
302       Math::PlanePath::PixelRings, Math::PlanePath::HexSpiral
303

HOME PAGE

305       <http://user42.tuxfamily.org/math-planepath/index.html>
306

LICENSE

308       Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
309       2020 Kevin Ryde
310
311       This file is part of Math-PlanePath.
312
313       Math-PlanePath is free software; you can redistribute it and/or modify
314       it under the terms of the GNU General Public License as published by
315       the Free Software Foundation; either version 3, or (at your option) any
316       later version.
317
318       Math-PlanePath is distributed in the hope that it will be useful, but
319       WITHOUT ANY WARRANTY; without even the implied warranty of
320       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
321       General Public License for more details.
322
323       You should have received a copy of the GNU General Public License along
324       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
325
326
327
328perl v5.36.0                      2022-07-22Math::PlanePath::TriangularHypot(3)
Impressum