NAME

Math::PlanePath::HexHypot -- points in order of hypotenuse distance

SYNOPSIS

use Math::PlanePath::HexHypot;
my $path = Math::PlanePath::HexHypot->new;
my ($x, $y) = $path->n_to_xy (123);

DESCRIPTION

This path visits points X,Y on a hexagonal grid in order of their distance from the origin 0,0 and anti-clockwise around from the X axis among those of equal distance,

         58    47    39    46    57                 4

      48    34    23    22    33    45              3

   40    24    16     9    15    21    38           2

49    25    10     4     3     8    20    44        1

   35    17     5     1     2    14    32      <- Y=0

50    26    11     6     7    13    31    55       -1

   41    27    18    12    19    30    43          -2

      51    36    28    29    37    54             -3

         60    52    42    53    61                -4

                      ^
-7 -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7

The points are put on a square grid similar to the HexSpiral. This means a Y=1 represents a height sqrt(3) for an equilateral triangle with base X=2, so the hypotenuse is

X^2 + (Y*sqrt(3))^2   =  X^2 + 3*Y^2

For example N=19 is at X=2,Y=-2 is sqrt(2**2+3*-2**2) = sqrt(4) from the origin. The next furthest is X=5,Y=1 at sqrt(7).

Equal Distances

Points with the same distance are taken in anti-clockwise order around from the X axis. For example X=4,Y=0 is sqrt(4) from the origin, as are the rotated X=2,Y=2 and X=--2,Y=2 etc in other sixths, for a total 6 points N=14 to N=19 all the same distance.

There can be more than one way for the same distance to arise, representing different solutions to the equation H = X^2 + 3*Y^2 in integer X,Y.

FUNCTIONS

$path = Math::PlanePath::HexHypot->new ()

Create and return a new hypot path object.

($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.

SEE ALSO

Math::PlanePath, Math::PlanePath::Hypot, Math::PlanePath::HypotOctant, Math::PlanePath::PixelRings