NAME

Math::PlanePath::OctagramSpiral -- integer points drawn around an octagram

SYNOPSIS

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

DESCRIPTION

This path makes a spiral around an octagram (8-pointed star),

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

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

Each loop is 16 longer than the previous. The 18-gonal numbers fall on the horizontal 18,51,100,etc at Y=-1.

The inner corners like 23, 31, 39, 47 are similar to the SquareSpiral path, but instead of going directly between them the octagram takes a detour out to make the points of the star. Those excursions make each loops 8 longer (1 per excursion), hence a step of 16 here as compared to 8 for the SquareSpiral.

FUNCTIONS

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

Create and return a new octagram 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 N in the path as centred in a square of side 1, so the entire plane is covered.

FORMULAS

X,Y to N

The symmetry of the octagram can be used by rotating a given X,Y back to the first star excursion such as N=19 to N=23. If Y is negative then rotate back by 180 degrees, then if X is negative rotate back by 90, and if Y>=X then by a further 45 degrees. Each such rotation, if needed, is counted as a multiple of the side-length to be added to the final N. For example at N=19 the side length is 2. Rotating by 180 degrees is 8 side lengths, by 90 degrees 4 sides, and by 45 degrees is 2 sides.

SEE ALSO

Math::PlanePath, Math::PlanePath::SquareSpiral, Math::PlanePath::PyramidSpiral

HOME PAGE

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

LICENSE

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