Math::PlanePath::AnvilSpiral -- integer points around an "anvil" shape
use Math::PlanePath::AnvilSpiral; my $path = Math::PlanePath::AnvilSpiral->new; my ($x, $y) = $path->n_to_xy (123);
This path makes a spiral around an anvil style shape,
...-78-77-76-75-74 4 / 49-48-47-46-45-44-43-42-41-40-39-38 73 3 \ / / 50 21-20-19-18-17-16-15-14 37 72 2 \ \ / / / 51 22 5--4--3--2 13 36 71 1 \ \ \ / / / / 52 23 6 1 12 35 70 <- Y=0 / / / \ \ \ 53 24 7--8--9-10-11 34 69 -1 / / \ \ 54 25-26-27-28-29-30-31-32-33 68 -2 / \ 55-56-57-58-59-60-61-62-63-64-65-66-67 -3 ^ -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7
The pentagonal numbers 1,5,12,22,etc, P(k) = (3k-1)*k/2 fall alternately on the X axis X>0, and on the Y=1 horizontal X<0.
Those pentagonals are always composites, from the factorization shown, and as noted in "Step 3 Pentagonals" in Math::PlanePath::PyramidRows, the immediately preceding P(k)-1 and P(k)-2 are also composites. So if plotting the primes on the spiral there's a 3-high horizontal blank line at Y=0,-1,-2 for positive X, and Y=1,2,3 for negative X (after the first few values).
Each loop around the spiral is 12 longer than the preceding. Because this is 4* more than the step=3 PyramidRows, straight lines on a PyramidRows like that are straight lines here but split into two parts.
The outward diagonal excursions are similar to the OctagramSpiral, but there's just 4 of them here where the OctagramSpiral has 8. This is reflected in the loop step in that the basic SquareSpiral is step 8, but by taking 4 excursions here that becomes 12, or in the OctagramSpiral 8 excursions add 8 to make step 16.
An optional wider parameter makes the path wider by starting with a horizontal section of given width. For example
wider
$path = Math::PlanePath::SquareSpiral->new (wider => 3);
gives
33-32-31-30-29-28-27-26-25-24-23 ... 2 \ / / 34 11-10--9--8--7--6--5 22 51 1 \ \ / / / 35 12 1--2--3--4 21 50 <- Y=0 / / \ \ 36 13-14-15-16-17-18-19-20 49 -1 / \ 37-38-39-40-41-42-43-44-45-46-47-48 -2 ^ -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5
The starting point 1 is shifted to the left by ceil(wider/2) places to keep the spiral centred on the origin X=0,Y=0. This the same starting offset as the SquareSpiral wider.
Widening doesn't change the nature of the straight lines which arise, it just rotates them around. Each loop is still 12 longer than the previous, as the widening is essentially a constant amount in each loop.
See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.
$path = Math::PlanePath::AnvilSpiral->new ()
$path = Math::PlanePath::AnvilSpiral->new (wider => $integer)
Create and return a new anvil spiral object. An optional wider parameter widens the spiral path, it defaults to 0 which is no widening.
($x,$y) = $path->n_to_xy ($n)
Return the X,Y coordinates of point number $n on the path.
$n
For $n < 1 the return is an empty list, it being considered the path starts at 1.
$n < 1
Math::PlanePath, Math::PlanePath::SquareSpiral, Math::PlanePath::OctagramSpiral, Math::PlanePath::HexSpiral
To install Math::PlanePath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::PlanePath
CPAN shell
perl -MCPAN -e shell install Math::PlanePath
For more information on module installation, please visit the detailed CPAN module installation guide.