.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Math::PlanePath::DiamondSpiral 3pm" .TH Math::PlanePath::DiamondSpiral 3pm "2021-01-23" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Math::PlanePath::DiamondSpiral \-\- integer points around a diamond shaped spiral .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Math::PlanePath::DiamondSpiral; \& my $path = Math::PlanePath::DiamondSpiral\->new; \& my ($x, $y) = $path\->n_to_xy (123); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This path makes a diamond shaped spiral. .PP .Vb 10 \& 19 3 \& / \e \& 20 9 18 2 \& / / \e \e \& 21 10 3 8 17 1 \& / / / \e \e \e \& 22 11 4 1\-\-\-2 7 16 <\- Y=0 \& \e \e \e / / \& 23 12 5\-\-\-6 15 ... \-1 \& \e \e / / \& 24 13\-\-14 27 \-2 \& \e / \& 25\-\-26 \-3 \& \& ^ \& \-3 \-2 \-1 X=0 1 2 3 .Ve .PP This is not simply the \f(CW\*(C`SquareSpiral\*(C'\fR rotated, it spirals around faster, with side lengths following a pattern 1,1,1,1, 2,2,2,2, 3,3,3,3, etc, if the flat kink at the bottom (like N=13 to N=14) is treated as part of the lower right diagonal. .PP Going diagonally on the sides as done here is like cutting the corners of the \f(CW\*(C`SquareSpiral\*(C'\fR, which is how it gets around in fewer steps than the \&\f(CW\*(C`SquareSpiral\*(C'\fR. See \f(CW\*(C`PentSpiralSkewed\*(C'\fR, \f(CW\*(C`HexSpiralSkewed\*(C'\fR and \&\f(CW\*(C`HeptSpiralSkewed\*(C'\fR for similar cutting just 3, 2 or 1 of the corners. .PP N=1,5,13,25,etc on the Y negative axis is the \&\*(L"centred square numbers\*(R" 2*k*(k+1)+1. .IX Xref "Centred square numbers" .SS "N Start" .IX Subsection "N Start" The default is to number points starting N=1 as shown above. An optional \&\f(CW\*(C`n_start\*(C'\fR can give a different start, with the same shape etc. For example to start at 0, .PP .Vb 10 \& n_start => 0 18 \& / \e \& 19 8 17 \& / / \e \e \& 20 9 2 7 16 \& / / / \e \e \e \& 21 10 3 0\-\- 1 6 15 \& \e \e \e / / \& 22 11 4\-\- 5 14 ... \& \e \e / / \& 23 12\-\-13 26 \& \e / \& 24\-\-25 .Ve .PP N=0,1,6,15,28,etc on the X axis is the hexagonal numbers k*(2k\-1). N=0,3,10,21,36,etc on the negative X axis is the hexagonal numbers of the \*(L"second kind\*(R" k*(2k\-1) for k<0. Combining those two is the triangular numbers 0,1,3,6,10,15,21,etc, k*(k+1)/2, on the X axis alternately positive and negative. .IX Xref "Hexagonal numbers" .PP N=0,2,8,18,etc on the Y axis is 2*squares, 2*Y^2. N=0,4,12,24,etc on the negative Y axis is 2*pronic, 2*Y*(Y+1). .IX Xref "Square numbers Pronic numbers" .SH "FUNCTIONS" .IX Header "FUNCTIONS" See \*(L"\s-1FUNCTIONS\*(R"\s0 in Math::PlanePath for behaviour common to all path classes. .ie n .IP """$path = Math::PlanePath::DiamondSpiral\->new ()""" 4 .el .IP "\f(CW$path = Math::PlanePath::DiamondSpiral\->new ()\fR" 4 .IX Item "$path = Math::PlanePath::DiamondSpiral->new ()" .PD 0 .ie n .IP """$path = Math::PlanePath::DiamondSpiral\->new (n_start => $n)""" 4 .el .IP "\f(CW$path = Math::PlanePath::DiamondSpiral\->new (n_start => $n)\fR" 4 .IX Item "$path = Math::PlanePath::DiamondSpiral->new (n_start => $n)" .PD Create and return a new diamond spiral object. .ie n .IP """($x,$y) = $path\->n_to_xy ($n)""" 4 .el .IP "\f(CW($x,$y) = $path\->n_to_xy ($n)\fR" 4 .IX Item "($x,$y) = $path->n_to_xy ($n)" Return the X,Y coordinates of point number \f(CW$n\fR on the path. .Sp For \f(CW\*(C`$n < 1\*(C'\fR the return is an empty list, it being considered the path starts at 1. .ie n .IP """$n = $path\->xy_to_n ($x,$y)""" 4 .el .IP "\f(CW$n = $path\->xy_to_n ($x,$y)\fR" 4 .IX Item "$n = $path->xy_to_n ($x,$y)" Return the point number for coordinates \f(CW\*(C`$x,$y\*(C'\fR. \f(CW$x\fR and \f(CW$y\fR are each rounded to the nearest integer, which has the effect of treating each point in the path as a square of side 1, so the entire plane is covered. .ie n .IP """($n_lo, $n_hi) = $path\->rect_to_n_range ($x1,$y1, $x2,$y2)""" 4 .el .IP "\f(CW($n_lo, $n_hi) = $path\->rect_to_n_range ($x1,$y1, $x2,$y2)\fR" 4 .IX Item "($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)" The returned range is exact, meaning \f(CW$n_lo\fR and \f(CW$n_hi\fR are the smallest and biggest in the rectangle. .SH "FORMULAS" .IX Header "FORMULAS" .SS "Rectangle to N Range" .IX Subsection "Rectangle to N Range" Within each row N increases as X moves away from the Y axis, and within each column similarly N increases as Y moves away from the X axis. So in a rectangle the maximum N is at one of the four corners. .PP .Vb 8 \& | \& x1,y2 M\-\-\-|\-\-\-\-M x2,y2 \& | | | \& \-\-\-\-\-\-\-O\-\-\-\-\-\-\-\-\- \& | | | \& | | | \& x1,y1 M\-\-\-|\-\-\-\-M x1,y1 \& | .Ve .PP For any two columns x1 and x2 with x1\-x1. This is so even when x1 and x2 are on the same side of the origin, ie. both positive or both negative. .PP For any two rows y1 and y2, the values in the part of the row with X>0 are bigger if y2>=\-y1, and in the part of the row with X<=0 it's y2>\-y1, or equivalently y2>=\-y1+1. So the biggest corner is at .PP .Vb 2 \& max_x = (x2 > \-x1 ? x2 : x1) \& max_y = (y2 >= \-y1+(max_x<=0) ? y2 : y1) .Ve .PP The minimum is similar but a little simpler. In any column the minimum is at Y=0, and in any row the minimum is at X=0. So at 0,0 if that's in the rectangle, or the edge on the side nearest the origin when not. .PP .Vb 3 \& min_x = / if x2 < 0 then x2 \& | if x1 > 0 then x1 \& \e else 0 \& \& min_y = / if y2 < 0 then y2 \& | if y1 > 0 then y1 \& \e else 0 .Ve .SH "OEIS" .IX Header "OEIS" Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include .Sp .RS 4 (etc) .RE .PP .Vb 8 \& n_start=1 \& A130883 N on X axis, 2*n^2\-n+1 \& A058331 N on Y axis, 2*n^2 + 1 \& A001105 N on column X=1, 2*n^2 \& A084849 N on X negative axis, 2*n^2+n+1 \& A001844 N on Y negative axis, centred squares 2*n^2+2n+1 \& A215471 N with >=5 primes among its 8 neighbours \& A215468 sum 8 neighbours N \& \& A217015 N permutation points order SquareSpiral rotate \-90, \& value DiamondSpiral N at each \& A217296 inverse permutation \& \& n_start=0 \& A010751 X coordinate, runs 1 inc, 2 dec, 3 inc, etc \& A305258 Y coordinate \& A053616 abs(Y), runs k to 0 to k \& A000384 N on X axis, hexagonal numbers \& A001105 N on Y axis, 2*n^2 (and cf similar A184636) \& A014105 N on X negative axis, second hexagonals \& A046092 N on Y negative axis, 2*pronic \& A003982 delta(abs(X)+abs(Y)), 1 when N on Y negative axis \& which is where move "outward" to next ring \& \& n_start=\-1 \& A188551 N positions of turns, from N=1 up \& A188552 and which are primes .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Math::PlanePath, Math::PlanePath::DiamondArms, Math::PlanePath::AztecDiamondRings, Math::PlanePath::SquareSpiral, Math::PlanePath::HexSpiralSkewed, Math::PlanePath::PyramidSides, Math::PlanePath::ToothpickSpiral .SH "HOME PAGE" .IX Header "HOME PAGE" .SH "LICENSE" .IX Header "LICENSE" Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde .PP This file is part of Math-PlanePath. .PP Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. .PP Math-PlanePath is distributed in the hope that it will be useful, but \&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with Math-PlanePath. If not, see .