.\" 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::SacksSpiral 3pm" .TH Math::PlanePath::SacksSpiral 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::SacksSpiral \-\- circular spiral squaring each revolution .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Math::PlanePath::SacksSpiral; \& my $path = Math::PlanePath::SacksSpiral\->new; \& my ($x, $y) = $path\->n_to_xy (123); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Sacks spiral by Robert Sacks is an Archimedean spiral with points N placed on the spiral so the perfect squares fall on a line going to the right. Read more at .IX Xref "Square numbers" .Sp .RS 4 .RE .PP An Archimedean spiral means radial distance a constant factor of the angle, and so each loop a constant distance out from the preceding loop, in this case 1 unit out. The polar coordinates are .PP .Vb 2 \& R = sqrt(N) \& theta = sqrt(N) * 2pi .Ve .PP which comes out roughly as .PP .Vb 3 \& 18 \& 19 11 10 17 \& 5 \& \& 20 12 6 2 \& 0 1 4 9 16 25 \& \& 3 \& 21 13 7 8 \& 15 24 \& 14 \& 22 23 .Ve .PP The X,Y positions returned are fractional, except for the perfect squares on the positive X axis at X=0,1,2,3,etc. The perfect squares are the closest points, at 1 unit apart. Other points are a little further apart. .PP The arms going to the right like N=5,10,17,etc or N=8,15,24,etc are constant offsets from the perfect squares, ie. d^2 + c for positive or negative integer c. To the left the central arm N=2,6,12,20,etc is the pronic numbers d^2 + d = d*(d+1), half way between the successive perfect squares. Other arms going to the left are offsets from that, ie. d*(d+1) + c for integer c. .IX Xref "Pronic numbers" .PP Euler's quadratic d^2+d+41 is one such arm going left. Low values loop around a few times before straightening out at about y=\-127. This quadratic has relatively many primes and in a plot of primes on the spiral it can be seen standing out from its surrounds. .PP Plotting various quadratic sequences of points can form attractive patterns. For example the triangular numbers k*(k+1)/2 come out as spiral arcs going clockwise and anti-clockwise. .IX Xref "Triangular numbers" .PP See \fIexamples/sacks\-xpm.pl\fR for a complete program plotting the spiral points to an \s-1XPM\s0 image. .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::SacksSpiral\->new ()""" 4 .el .IP "\f(CW$path = Math::PlanePath::SacksSpiral\->new ()\fR" 4 .IX Item "$path = Math::PlanePath::SacksSpiral->new ()" Create and return a new path 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 \&\f(CW$n\fR can be any value \f(CW\*(C`$n >= 0\*(C'\fR and fractions give positions on the spiral in between the integer points. .Sp For \f(CW\*(C`$n < 0\*(C'\fR the return is an empty list, it being considered there are no negative points in the spiral. .ie n .IP """$rsquared = $path\->n_to_rsquared ($n)""" 4 .el .IP "\f(CW$rsquared = $path\->n_to_rsquared ($n)\fR" 4 .IX Item "$rsquared = $path->n_to_rsquared ($n)" Return the radial distance R^2 of point \f(CW$n\fR, or \f(CW\*(C`undef\*(C'\fR if there's no point \f(CW$n\fR. This is simply \f(CW$n\fR itself, since R=sqrt(N). .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 an integer point number for coordinates \f(CW\*(C`$x,$y\*(C'\fR. Each integer N is considered the centre of a circle of diameter 1 and an \f(CW\*(C`$x,$y\*(C'\fR within that circle returns N. .Sp The unit spacing of the spiral means those circles don't overlap, but they also don't cover the plane and if \f(CW\*(C`$x,$y\*(C'\fR is not within one then the return is \f(CW\*(C`undef\*(C'\fR. .SS "Descriptive Methods" .IX Subsection "Descriptive Methods" .ie n .IP """$dx = $path\->dx_minimum()""" 4 .el .IP "\f(CW$dx = $path\->dx_minimum()\fR" 4 .IX Item "$dx = $path->dx_minimum()" .PD 0 .ie n .IP """$dx = $path\->dx_maximum()""" 4 .el .IP "\f(CW$dx = $path\->dx_maximum()\fR" 4 .IX Item "$dx = $path->dx_maximum()" .ie n .IP """$dy = $path\->dy_minimum()""" 4 .el .IP "\f(CW$dy = $path\->dy_minimum()\fR" 4 .IX Item "$dy = $path->dy_minimum()" .ie n .IP """$dy = $path\->dy_maximum()""" 4 .el .IP "\f(CW$dy = $path\->dy_maximum()\fR" 4 .IX Item "$dy = $path->dy_maximum()" .PD dX and dY have minimum \-pi=\-3.14159 and maximum pi=3.14159. The loop beginning at N=2^k is approximately a polygon of 2k+1 many sides and radius R=k. Each side is therefore .Sp .Vb 3 \& side = sin(2pi/(2k+1)) * k \& \-> 2pi/(2k+1) * k \& \-> pi .Ve .ie n .IP """$str = $path\->figure ()""" 4 .el .IP "\f(CW$str = $path\->figure ()\fR" 4 .IX Item "$str = $path->figure ()" Return \*(L"circle\*(R". .SH "FORMULAS" .IX Header "FORMULAS" .SS "Rectangle to N Range" .IX Subsection "Rectangle to N Range" R=sqrt(N) here is the same as in the \f(CW\*(C`TheodorusSpiral\*(C'\fR and the code is shared here. See \*(L"Rectangle to N Range\*(R" in Math::PlanePath::TheodorusSpiral. .PP The accuracy could be improved here by taking into account the polar angle of the corners which are candidates for the maximum radius. On the X axis the stripes of N are from X\-0.5 to X+0.5, but up on the Y axis it's 0.25 further out at Y\-0.25 to Y+0.75. The stripe the corner falls in can thus be biased by theta expressed as a fraction 0 to 1 around the plane. .PP An exact theta 0 to 1 would require an arctan, but approximations 0, 0.25, 0.5, 0.75 from the quadrants, or eighths of the plane by X>Y etc diagonals. As noted for the Theodorus spiral the over-estimate from ignoring the angle is at worst R many points, which corresponds to a full loop here. Using the angle would reduce that to 1/4 or 1/8 etc of a loop. .SH "SEE ALSO" .IX Header "SEE ALSO" Math::PlanePath, Math::PlanePath::PyramidRows, Math::PlanePath::ArchimedeanChords, Math::PlanePath::TheodorusSpiral, Math::PlanePath::VogelFloret .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 .