NAME
Math::PlanePath::DiamondSpiral -- integer points in a diamond shape
SYNOPSIS
use Math::PlanePath::DiamondSpiral;
my $path = Math::PlanePath::DiamondSpiral->new;
my ($x, $y) = $path->n_to_xy (123);
DESCRIPTION
This path makes a diamond shaped spiral.
19 ..
20 9 18 ..
21 10 3 8 17 ..
22 11 4 1 2 7 16 .. <- y=0
23 12 5 6 15 ..
24 13 14 ..
25 26
^
x=0
This is not simply the SquareSpiral rotated, it spirals around faster, with side lengths following a pattern 1,1,1,1, 2,2,2,2, 3,3,3,3, if the flat kink at the bottom (like 13 to 14) is treated as part of the lower right diagonal.
The triangular number 3,6,10,15,21,etc fall alternately on the horizontal to the left at y=1 and the right at y=-1 (one term to the left then one term to the right).
Going diagonal on the sides is like cutting the corners going around a SquareSpiral, which is how it gets around in fewer steps. See the HexSpiralSkewed for similar cutting just two of the four corners.
FUNCTIONS
$path = Math::PlanePath::DiamondSpiral->new ()
-
Create and return a new DiamondSpiral spiral 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 path starts at 1. $n = $path->xy_to_n ($x,$y)
-
Return the point number for coordinates
$x,$y
.$x
and$y
are each rounded to the nearest integer, which has the effect of treating each point in the path as a square of side 1, so the entire plane is covered.
SEE ALSO
Math::PlanePath, Math::PlanePath::SquareSpiral, Math::PlanePath::HexSpiralSkewed, Math::PlanePath::PyramidSides
HOME PAGE
http://user42.tuxfamily.org/math-planepath/index.html
LICENSE
Math-PlanePath is Copyright 2010, 2011 Kevin Ryde
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/>.