1Math::PlanePath::Hypot(U3s)er Contributed Perl DocumentatMiaotnh::PlanePath::Hypot(3)
2
3
4

NAME

6       Math::PlanePath::Hypot -- points in order of hypotenuse distance
7

SYNOPSIS

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

DESCRIPTION

14       This path visits integer points X,Y in order of their distance from the
15       origin 0,0, or anti-clockwise from the X axis among those of equal
16       distance,
17
18                           84  73  83                         5
19                   74  64  52  47  51  63  72                 4
20               75  59  40  32  27  31  39  58  71             3
21               65  41  23  16  11  15  22  38  62             2
22           85  53  33  17   7   3   6  14  30  50  82         1
23           76  48  28  12   4   1   2  10  26  46  70    <- Y=0
24           86  54  34  18   8   5   9  21  37  57  89        -1
25               66  42  24  19  13  20  25  45  69            -2
26               77  60  43  35  29  36  44  61  81            -3
27                   78  67  55  49  56  68  80                -4
28                           87  79  88                        -5
29
30                                ^
31           -5  -4  -3  -2  -1  X=0  1   2   3   4   5
32
33       For example N=58 is at X=4,Y=-1 is sqrt(4*4+1*1) = sqrt(17) from the
34       origin.  The next furthest from the origin is X=3,Y=3 at sqrt(18).
35
36       See "TriangularHypot" for points in order of X^2+3*Y^2, or
37       "DiamondSpiral" and "PyrmaidSides" in order of plain sum X+Y.
38
39   Equal Distances
40       Points with the same distance are taken in anti-clockwise order around
41       from the X axis.  For example X=3,Y=1 is sqrt(10) from the origin, as
42       are the swapped X=1,Y=3, and X=-1,Y=3 etc in other quadrants, for a
43       total 8 points N=30 to N=37 all the same distance.
44
45       When one of X or Y is 0 there's no negative, so just four negations
46       like N=10 to 13 points X=2,Y=0 through X=0,Y=-2.  Or on the diagonal
47       X==Y there's no swap, so just four like N=22 to N=25 points X=3,Y=3
48       through X=3,Y=-3.
49
50       There can be more than one way for the same distance to arise.  A
51       Pythagorean triple like 3^2 + 4^2 == 5^2 has 8 points from the 3,4,
52       then 4 points from the 5,0 giving a total 12 points N=70 to N=81.
53       Other combinations like 20^2 + 15^2 == 24^2 + 7^2 occur too, and also
54       with more than two different ways to have the same sum.
55
56   Multiples of 4
57       The first point of a given distance from the origin is either on the X
58       axis or somewhere in the first octant.  The row Y=1 just above the axis
59       is the first of its equals from X>=2 onwards, and similarly further
60       rows for big enough X.
61
62       There's always a multiple of 4 many points with the same distance so
63       the first point has N=4*k+2, and similarly on the negative X side
64       N=4*j, for some k or j.  If you plot the prime numbers on the path then
65       those even N's (composites) are gaps just above the positive X axis,
66       and on or just below the negative X axis.
67
68   Circle Lattice
69       Gauss's circle lattice problem asks how many integer X,Y points there
70       are within a circle of radius R.
71
72       The points on the X axis N=2,10,26,46, etc are the first for which
73       X^2+Y^2==R^2 (integer X==R).  Adding option "n_start=>0" to make them
74       each 1 less gives the number of points strictly inside, ie. X^2+Y^2 <
75       R^2.
76
77       The last point satisfying X^2+Y^2==R^2 is either in the octant below
78       the X axis, or is on the negative Y axis.  Those N's are the number of
79       points X^2+Y^2<=R^2, Sloane's A000328.
80
81       When that A000328 sequence is plotted on the path a straight line can
82       be seen in the fourth quadrant extending down just above the diagonal.
83       It arises from multiples of the Pythagorean 3^2 + 4^2, first X=4,Y=-3,
84       then X=8,Y=-6, etc X=4*k,Y=-3*k.  But sometimes the multiple is not the
85       last among those of that 5*k radius, so there's gaps in the line.  For
86       example 20,-15 is not the last since because 24,-7 is also 25 away from
87       the origin.
88
89   Even Points
90       Option "points => "even"" visits just the even points, meaning the sum
91       X+Y even, so X,Y both even or both odd.
92
93           points => "even"
94
95                 52    40    39    51             5
96              47    32    23    31    46          4
97           53    27    16    15    26    50       3
98              33    11     7    10    30          2
99           41    17     3     2    14    38       1
100              24     8     1     6    22     <- Y=0
101           42    18     4     5    21    45      -1
102              34    12     9    13    37         -2
103           54    28    19    20    29    57      -3
104              48    35    25    36    49         -4
105                 55    43    44    56            -5
106
107                           ^
108           -5 -4 -3 -2 -1 X=0 1  2  3  4  5
109
110       Even points can be mapped to all points by a 45 degree rotate and flip.
111       N=1,6,22,etc on the X axis here is on the X=Y diagonal of all-points.
112       And conversely N=1,2,10,26,etc on the X=Y diagonal here is the X axis
113       of all-points.
114
115       The sets of points with equal hypotenuse are the same in the even and
116       all, but the flip takes them in a reversed order.
117
118   Odd Points
119       Option "points => "odd"" visits just the odd points, meaning sum X+Y
120       odd, so X,Y one odd the other even.
121
122           points => "odd"
123
124
125                    71    55    54    70                6
126                 63    47    36    46    62             5
127              64    37    27    26    35    61          4
128           72    38    19    14    18    34    69       3
129              48    20     7     6    17    45          2
130           56    28     8     2     5    25    53       1
131              39    15     3  +  1    13    33     <- Y=0
132           57    29     9     4    12    32    60      -1
133              49    21    10    11    24    52         -2
134           73    40    22    16    23    44    76      -3
135              65    41    30    31    43    68         -4
136                 66    50    42    51    67            -5
137                    74    58    59    75               -6
138
139                              ^
140           -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6
141
142       Odd points can be mapped to all points by a 45 degree rotate and a
143       shift X-1,Y+1 to put N=1 at the origin.  The effect of that shift is as
144       if the hypot measure in "all" points was (X-1/2)^2+(Y-1/2)^2 and for
145       that reason the sets of points with equal hypots are not the same in
146       odd and all.
147

FUNCTIONS

149       See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
150       classes.
151
152       "$path = Math::PlanePath::Hypot->new ()"
153       "$path = Math::PlanePath::Hypot->new (points => $str), n_start => $n"
154           Create and return a new hypot path object.  The "points" option can
155           be
156
157               "all"         all integer X,Y (the default)
158               "even"        only points with X+Y even
159               "odd"         only points with X+Y odd
160
161       "($x,$y) = $path->n_to_xy ($n)"
162           Return the X,Y coordinates of point number $n on the path.
163
164           For "$n < 1" the return is an empty list, it being considered the
165           first point at X=0,Y=0 is N=1.
166
167           Currently it's unspecified what happens if $n is not an integer.
168           Successive points are a fair way apart, so it may not make much
169           sense to say give an X,Y position in between the integer $n.
170
171       "$n = $path->xy_to_n ($x,$y)"
172           Return an integer point number for coordinates "$x,$y".  Each
173           integer N is considered the centre of a unit square and an "$x,$y"
174           within that square returns N.
175
176           For "even" and "odd" options only every second square in the plane
177           has an N and if "$x,$y" is a position not covered then the return
178           is "undef".
179

FORMULAS

181       The calculations are not particularly efficient currently.  Private
182       arrays are built similar to what's described for "HypotOctant", but
183       with replication for negative and swapped X,Y.
184

OEIS

186       Entries in Sloane's Online Encyclopedia of Integer Sequences related to
187       this path include
188
189           <http://oeis.org/A051132> (etc)
190
191           points="all", n_start=0
192             A051132    N on X axis, being count points norm < X^2
193
194           points="odd"
195             A005883    count of points with norm==4*n+1
196

SEE ALSO

198       Math::PlanePath, Math::PlanePath::HypotOctant,
199       Math::PlanePath::TriangularHypot, Math::PlanePath::PixelRings,
200       Math::PlanePath::PythagoreanTree
201

HOME PAGE

203       <http://user42.tuxfamily.org/math-planepath/index.html>
204

LICENSE

206       Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Kevin Ryde
207
208       This file is part of Math-PlanePath.
209
210       Math-PlanePath is free software; you can redistribute it and/or modify
211       it under the terms of the GNU General Public License as published by
212       the Free Software Foundation; either version 3, or (at your option) any
213       later version.
214
215       Math-PlanePath is distributed in the hope that it will be useful, but
216       WITHOUT ANY WARRANTY; without even the implied warranty of
217       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
218       General Public License for more details.
219
220       You should have received a copy of the GNU General Public License along
221       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
222
223
224
225perl v5.32.0                      2020-07-28         Math::PlanePath::Hypot(3)
Impressum