Math::PlanePath::Hypot -- points in order of hypotenuse distance
use Math::PlanePath::Hypot; my $path = Math::PlanePath::Hypot->new; my ($x, $y) = $path->n_to_xy (123);
This path visits integer points X,Y in order of their distance from the origin 0,0, or anti-clockwise from the X axis among those of equal distance,
84 73 83 5 74 64 52 47 51 63 72 4 75 59 40 32 27 31 39 58 71 3 65 41 23 16 11 15 22 38 62 2 85 53 33 17 7 3 6 14 30 50 82 1 76 48 28 12 4 1 2 10 26 46 70 <- Y=0 86 54 34 18 8 5 9 21 37 57 89 -1 66 42 24 19 13 20 25 45 69 -2 77 60 43 35 29 36 44 61 81 -3 78 67 55 49 56 68 80 -4 87 79 88 -5 ^ -5 -4 -3 -2 -1 X=0 1 2 3 4 5
For example N=58 is at X=4,Y=-1 is sqrt(4*4+1*1) = sqrt(17) from the origin. The next furthest from the origin is X=3,Y=3 at sqrt(18).
See TriangularHypot
for points in order of X^2+3*Y^2, or DiamondSpiral
and PyrmaidSides
in order of plain sum X+Y.
Points with the same distance are taken in anti-clockwise order around from the X axis. For example X=3,Y=1 is sqrt(10) from the origin, as are the swapped X=1,Y=3, and X=-1,Y=3 etc in other quadrants, for a total 8 points N=30 to N=37 all the same distance.
When one of X or Y is 0 there's no negative, so just four negations like N=10 to 13 points X=2,Y=0 through X=0,Y=-2. Or on the diagonal X==Y there's no swap, so just four like N=22 to N=25 points X=3,Y=3 through X=3,Y=-3.
There can be more than one way for the same distance to arise. A Pythagorean triple like 3^2 + 4^2 == 5^2 has 8 points from the 3,4, then 4 points from the 5,0 giving a total 12 points N=70 to N=81. Other combinations like 20^2 + 15^2 == 24^2 + 7^2 occur too, and also with more than two different ways to have the same sum.
The first point of a given distance from the origin is either on the X axis or somewhere in the first octant. The row Y=1 just above the axis is the first of its equals from X>=2 onwards, and similarly further rows for big enough X.
There's always a multiple of 4 many points with the same distance so the first point has N=4*k+2, and similarly on the negative X side N=4*j, for some k or j. If you plot the prime numbers on the path then those even N's (composites) are gaps just above the positive X axis, and on or just below the negative X axis.
Gauss's circle lattice problem asks how many integer X,Y points there are within a circle of radius R.
The points on the X axis N=2,10,26,46, etc are the first for which X^2+Y^2==R^2 (integer X==R). Adding option n_start=>0
to make them each 1 less gives the number of points strictly inside, ie. X^2+Y^2 < R^2.
The last point satisfying X^2+Y^2==R^2 is either in the octant below the X axis, or is on the negative Y axis. Those N's are the number of points X^2+Y^2<=R^2, Sloane's A000328.
When that A000328 sequence is plotted on the path a straight line can be seen in the fourth quadrant extending down just above the diagonal. It arises from multiples of the Pythagorean 3^2 + 4^2, first X=4,Y=-3, then X=8,Y=-6, etc X=4*k,Y=-3*k. But sometimes the multiple is not the last among those of that 5*k radius, so there's gaps in the line. For example 20,-15 is not the last since because 24,-7 is also 25 away from the origin.
Option points => "even"
visits just the even points, meaning the sum X+Y even, so X,Y both even or both odd.
points => "even" 52 40 39 51 5 47 32 23 31 46 4 53 27 16 15 26 50 3 33 11 7 10 30 2 41 17 3 2 14 38 1 24 8 1 6 22 <- Y=0 42 18 4 5 21 45 -1 34 12 9 13 37 -2 54 28 19 20 29 57 -3 48 35 25 36 49 -4 55 43 44 56 -5 ^ -5 -4 -3 -2 -1 X=0 1 2 3 4 5
Even points can be mapped to all points by a 45 degree rotate and flip. N=1,6,22,etc on the X axis here is on the X=Y diagonal of all-points. And conversely N=1,2,10,26,etc on the X=Y diagonal here is the X axis of all-points.
The sets of points with equal hypotenuse are the same in the even and all, but the flip takes them in a reversed order.
Option points => "odd"
visits just the odd points, meaning sum X+Y odd, so X,Y one odd the other even.
points => "odd" 71 55 54 70 6 63 47 36 46 62 5 64 37 27 26 35 61 4 72 38 19 14 18 34 69 3 48 20 7 6 17 45 2 56 28 8 2 5 25 53 1 39 15 3 + 1 13 33 <- Y=0 57 29 9 4 12 32 60 -1 49 21 10 11 24 52 -2 73 40 22 16 23 44 76 -3 65 41 30 31 43 68 -4 66 50 42 51 67 -5 74 58 59 75 -6 ^ -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6
Odd points can be mapped to all points by a 45 degree rotate and a shift X-1,Y+1 to put N=1 at the origin. The effect of that shift is as if the hypot measure in "all" points was (X-1/2)^2+(Y-1/2)^2 and for that reason the sets of points with equal hypots are not the same in odd and all.
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::Hypot->new ()
$path = Math::PlanePath::Hypot->new (points => $str), n_start => $n
Create and return a new hypot path object. The points
option can be
"all" all integer X,Y (the default) "even" only points with X+Y even "odd" only points with X+Y odd
($x,$y) = $path->n_to_xy ($n)
Return the X,Y coordinates of point number $n
on the path.
For $n < 1
the return is an empty list, it being considered the first point at X=0,Y=0 is N=1.
Currently it's unspecified what happens if $n
is not an integer. Successive points are a fair way apart, so it may not make much sense to say give an X,Y position in between the integer $n
.
$n = $path->xy_to_n ($x,$y)
Return an integer point number for coordinates $x,$y
. Each integer N is considered the centre of a unit square and an $x,$y
within that square returns N.
For "even" and "odd" options only every second square in the plane has an N and if $x,$y
is a position not covered then the return is undef
.
The calculations are not particularly efficient currently. Private arrays are built similar to what's described for HypotOctant
, but with replication for negative and swapped X,Y.
Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include
http://oeis.org/A051132 (etc)
points="all", n_start=0 A051132 N on X axis, being count points norm < X^2 points="odd" A005883 count of points with norm==4*n+1
Math::PlanePath, Math::PlanePath::HypotOctant, Math::PlanePath::TriangularHypot, Math::PlanePath::PixelRings, Math::PlanePath::PythagoreanTree
http://user42.tuxfamily.org/math-planepath/index.html
Copyright 2011, 2012, 2013, 2014, 2015 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.