NAME
Math::PlanePath::TriangularHypot -- points of triangular lattice in order of hypotenuse distance
SYNOPSIS
use Math::PlanePath::TriangularHypot;
my $path = Math::PlanePath::TriangularHypot->new;
my ($x, $y) = $path->n_to_xy (123);
DESCRIPTION
This path visits X,Y points on a triangular "A2" lattice 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 lattice is put on a square X,Y grid using every second point per "Triangular Lattice" in Math::PlanePath. With a scaling X/2, Y*sqrt(3)/2 to give equilateral triangles with side length 1 the X,Y distance from the origin is
dist^2 = (X/2^2 + (Y*sqrt(3)/2)^2 = (X^2 + 3*Y^2) / 4
For example N=19 at X=2,Y=-2 is sqrt((2**2+3*-2**2)/4) = sqrt(4) from the origin. The next smallest after that is X=5,Y=1 at sqrt(7). The key part is X^2 + 3*Y^2 as the distance measure to order the points.
Equal Distances
Points with the same distance are taken in anti-clockwise order around from the X axis. For example N=14 at 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.
In general there's either 6 or 12 symmetric points. 6 when on the six radial lines X=0, X=Y or X=-Y. And 6 also when on the six radial lines Y=0, X=3*Y or X=-3*Y (these are midway between the first six). And then 12 for anything in the twelve slices in between those lines, for example the first being N=20 through N=31 all at sqrt(28).
There can also be multiple ways for the same distance to arise, but the 6-way or 12-way symmetry means always a multiple of 6 or 12.
FUNCTIONS
$path = Math::PlanePath::TriangularHypot->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 as 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.Only every second square in the plane has an N, being those where X,Y both odd or both even. If
$x,$y
is a position without an N, ie. one of X,Y odd the other even, then the return isundef
.
SEE ALSO
Math::PlanePath, Math::PlanePath::Hypot, Math::PlanePath::HypotOctant, Math::PlanePath::PixelRings, Math::PlanePath::HexSpiral
HOME PAGE
http://user42.tuxfamily.org/math-planepath/index.html
LICENSE
Copyright 2010, 2011 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/>.