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

NAME

Math::PlanePath::PyramidRows -- points stacked up in a pyramid

SYNOPSIS

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

DESCRIPTION

This path arranges points in successively wider rows going upwards so as to form an upside-down pyramid.

    17  18  19  20  21  22  23  24  25         4
        10  11  12  13  14  15  16             3
             5   6   7   8   9                 2
                 2   3   4                     1
                     1                   <-  y=0

    -4  -3  -2  -1  x=0  1   2   3   4 ...

The right edge 1,4,9,16,etc is the perfect squares. The vertical 2,6,12,20,etc at x=-1 is the pronic numbers s*(s+1), half way between those successive squares.

Each row is 2 longer than the previous and in that respect this is the same as the Corner and SacksSpiral paths. Diagonals in the pyramid correspond to Sacks spiral arms going to the right, and verticals in the pyramid correspond to arms going left.

As with all the +2 stride paths a plot of the triangular numbers s*(s+1)/2 makes an attractive arcing pattern.

FUNCTIONS

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

Create and return a new path object.

($x,$y) = $path->n_to_xy ($n)

Return the x,y coordinates of point number $n on the path.

For $n < 0 the return is an empty list, it being considered there are no negative points in the pyramid.

$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 pyramid as a square of side 1. If $x,$y is outside the pyramid the return is undef.

SEE ALSO

Math::PlanePath, Math::PlanePath::PyramidSides, Math::PlanePath::Corner, Math::PlanePath::SacksSpiral

HOME PAGE

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

LICENSE

Math-PlanePath is Copyright 2010 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/>.