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.

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