Math::PlanePath::HeptSpiralSkewed -- integer points around a skewed seven sided spiral
use Math::PlanePath::HeptSpiralSkewed; my $path = Math::PlanePath::HeptSpiralSkewed->new; my ($x, $y) = $path->n_to_xy (123);
This path makes a seven-sided spiral by cutting one corner of a square
31-30-29-28 3 | \ 32 14-13-12 27 2 | | \ \ 33 15 4--3 11 26 1 | | | \ \ \ 34 16 5 1--2 10 25 <- Y=0 | | | | | 35 17 6--7--8--9 24 -1 | | | 36 18-19-20-21-22-23 -2 | 37-38-39-40-41-... -3 ^ -3 -2 -1 X=0 1 2 3
The path is as if around a heptagon, with the left and bottom here as two sides of the heptagon straightened out, and the flat top here skewed across to fit a square grid.
The default is to number points starting N=1 as shown above. An optional n_start
can give a different start, in the same pattern. For example to start at 0,
30 29 28 27 n_start => 0 31 13 12 11 26 32 14 3 2 10 25 33 15 4 0 1 9 24 34 16 5 6 7 8 23 35 17 18 19 20 21 22 36 37 38 39 40 ...
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::HeptSpiralSkewed->new ()
$path = Math::PlanePath::HeptSpiralSkewed->new (n_start => $n)
Create and return a new path object.
$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.
It's convenient to work in terms of Nstart=0 and to take each loop as beginning on the South-West diagonal,
top length = d 30-29-28-27 | \ 31 26 diagonal length = d left | \ length 32 25 = 2*d | \ 33 0 24 | | right 34 . 23 length = d-1 | | 35 17-18-19-20-21-22 | . bottom length = 2*d-1
The SW diagonal is N=0,5,17,36,etc which is
N = (7d-11)*d/2 + 2 # starting d=1 first loop
This can be inverted to get d from N
d = floor( (sqrt(56*N+9)+11)/14 )
The side lengths are as shown above. The first loop is d=1 and for it the "right" vertical length is zero, so no such side on that first loop 0 <= N < 5.
Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include
http://oeis.org/A192136 (etc)
n_start=1 A140065 N on Y axis n_start=0 A001106 N on X axis, 9-gonal numbers A218471 N on Y axis A022265 N on X negative axis A179986 N on Y negative axis, second 9-gonals A195023 N on X=Y diagonal A022264 N on North-West diagonal A186029 N on South-West diagonal A024966 N on South-East diagonal
Math::PlanePath, Math::PlanePath::SquareSpiral, Math::PlanePath::PentSpiralSkewed, Math::PlanePath::HexSpiralSkewed
http://user42.tuxfamily.org/math-planepath/index.html
Copyright 2010, 2011, 2012, 2013, 2014 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/>.