++ed by:
EGOR BHANN

2 PAUSE users

Kevin Ryde
and 1 contributors

NAME

Math::PlanePath::PentSpiral -- integer points in a pentagonal shape

SYNOPSIS

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

DESCRIPTION

This path makes a pentagonal (five-sided) spiral with points spread out to fit on a square grid.

                      22                              3
                           
                23    10    21                        2
                                 
          24    11     3     9    20                  1
                                       
    25    12     4     1     2     8    19       <- y=0
                                        
       26    13     5     6     7    18    ...       -1
                                           
          27    14    15    16    17    33           -2
                                        
             28    29    30    31    32              -2


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

Each horizontal gap is 2, so for instance n=1 is at x=0,y=0 then n=2 is at x=2,y=0. The lower diagonals are 1 across and 1 down, so n=17 is at x=4,y=-2 and n=18 is x=5,y=-1. But the upper angles go 2 across and 1 up, so n=20 is x=4,y=1 then n=21 is x=2,y=2.

The effect is to make the sides equal length, except for a kink at the lower right corner. Only every second square in the plane is used. In the top half (y>=0) those squares line up, in the lower half (y<0) they're offset on alternate rows.

FUNCTIONS

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

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

Create and return a new pentagon 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.

SEE ALSO

Math::PlanePath, Math::PlanePath::PentSpiralSkewed, 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/>.