Math::PlanePath::DiagonalsAlternating -- points in diagonal stripes of alternating directions
use Math::PlanePath::DiagonalsAlternating; my $path = Math::PlanePath::DiagonalsAlternating->new; my ($x, $y) = $path->n_to_xy (123);
This path follows successive diagonals going from the Y axis down to the X axis and then back again,
7 | 29 6 | 28 30 5 | 16 27 31 4 | 15 17 26 ... 3 | 7 14 18 25 2 | 6 8 13 19 24 1 | 2 5 9 12 20 23 Y=0 | 1 3 4 10 11 21 22 +---------------------------- X=0 1 2 3 4 5 6
The triangular numbers 1,3,6,10,etc, k*(k+1)/2, fall alternately on the X axis and Y axis. So 1,6,15,28,etc on the Y axis, and 3,10,21,36,etc on the X axis. Those on the Y axis are the hexagonal numbers j*(2j-1) and those on the X axis are the hexagonals of the second kind j*(2j+1).
See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.
$path = Math::PlanePath::DiagonalsAlternating->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.
$n
For $n < 1 the return is an empty list, it being considered the path begins at 1.
$n < 1
Within each row increasing X is increasing N, and in each column increasing Y is increasing N. So in a rectangle the lower left corner is the minimum N and the upper right is the maximum N.
Math::PlanePath, Math::PlanePath::Diagonals
http://user42.tuxfamily.org/math-planepath/index.html
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/>.
To install Math::PlanePath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::PlanePath
CPAN shell
perl -MCPAN -e shell install Math::PlanePath
For more information on module installation, please visit the detailed CPAN module installation guide.