The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::PlanePath::PyramidSpiral -- integer points drawn around a pyramid

SYNOPSIS

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

DESCRIPTION

This path makes a pyramid shaped spiral,

                      31                         3
                     /  \
                   32 13 30                      2
                  /  /  \  \
                33 14  3 12 29                   1
               /  /  /  \  \  \
             34 15  4  1--2 11 28 ...        <- Y=0
            /  /  /           \  \  \
          35 16  5--6--7--8--9-10 27 52         -1
         /  /                       \  \
       36 17-18-19-20-21-22-23-24-25-26 51      -2
      /                                   \
    37-38-39-40-41-42-43-44-45-46-47-48-49-50   -3

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

The perfect squares 1,4,9,16 fall one before the bottom left corner of each loop, and the pronic numbers 2,6,12,20,30,etc are the vertical upwards from x=1.

Square Spiral

This spiral goes around at the same rate as the SquareSpiral, and is as if two corners are cut off (like the DiamondSpiral) and two others extended (like the OctagramSpiral). The net effect is the same looping rate but the points pushed around a bit.

Taking the points up to a perfect square shows the similarity. The two triangular cut-off corners marked "*" are matched by the two triangular extensions.

            +--------------------+   7x7 square
            | *  *  * 31  *  *  *|
            | *  * 32 13 30  *  *|
            | * 33 14  3 12 29  *|
            |34 15  4  1  2 11 28|
          35|16  5  6  7  8  9 10|27
       36 17|18 19 20 21 22 23 24|25 26
    37 38 39|40 41 42 43 44 45 46|47 48 49
            +--------------------+

FUNCTIONS

See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.

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

Create and return a new pyramid 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 N in the path as centred in a square of side 1, so the entire plane is covered.

SEE ALSO

Math::PlanePath, Math::PlanePath::SquareSpiral, Math::PlanePath::PyramidRows

HOME PAGE

http://user42.tuxfamily.org/math-planepath/index.html

LICENSE

Copyright 2010, 2011, 2012 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/>.