NAME

Math::PlanePath::ToothpickSpiral -- integer points in stair-step diagonal stripes

SYNOPSIS

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

DESCRIPTION

This path is length=2 toothpicks placed in an anti-clockwise spiral. A single new toothpick is added at an end of the preceding. Each is as close to the origin as possible without toothpicks overlapping. Ends may touch, but no overlapping.

       |
       3---2---
   |   |   |
   5---4-- 1  ...
   |   |   |   |
---6---7 -10--11
       |   |   |
     --8---9
           |

The result is a stair-step diamond spiral starting vertically. As per the other toothpick paths the vertical toothpicks are "even" points X=Ymod2 and horizontal toothpicks "odd" points X!=Ymod2.

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

             ^
-4 -3 -2 -1 X=0 1  2  3  4

N=1,15,45,etc on the X=Y leading diagonal and N=6,28,66,etc on the X=Y-1 South-West diagonal are the hexagonal numbers k*(2k-1). The odd hexagonals are to the North-East and the even hexagonals to the South-West.

The hexagonal numbers of the "second kind" which are k*(2k-1) for k negative. They fall similarly on the X=-Y-1 North-West and X=-Y South-East diagonals.

N Start

The default is to number points starting N=1 as shown above. An optional n_start can give a different numbering of the same shape. For example to start at 0,

          18-17          n_start => 0 
          |  |    
      20-19 16-15 
       |        |    
   22-21  2--1 14-13 
    |     |  |     | 
24-23  4--3  0 11-12 
 |     |        |
25-26  5--6  9-10
    |     |  | 
   27-28  7--8 
       |
      ...

FUNCTIONS

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

$path = Math::PlanePath::ToothpickSpiral->new ()
$path = Math::PlanePath::ToothpickSpiral->new (n_start => $n)

Create and return a new staircase path object.

Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include

n_start=1 (the default)
  A014634     N on diagonal X=Y, odd hexagonals
  A033567     N on diagonal North-West
  A185438     N on diagonal South-West
  A188135     N on diagonal South-East

n_start=0
   A033587    N on diagonal X=Y
   A014635    N on diagonal South-West, even hexagonals
   A033585    N on diagonal South-East

SEE ALSO

Math::PlanePath, Math::PlanePath::Staircase, Math::PlanePath::DiamondSpiral

HOME PAGE

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

LICENSE

Copyright 2013, 2014, 2015 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/>.