.\" 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::MultipleRings 3pm" .TH Math::PlanePath::MultipleRings 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::MultipleRings \-\- rings of multiples .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Math::PlanePath::MultipleRings; \& my $path = Math::PlanePath::MultipleRings\->new (step => 6); \& my ($x, $y) = $path\->n_to_xy (123); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This path puts points on concentric rings. Each ring has \*(L"step\*(R" many points more than the previous and the first is also \*(L"step\*(R". For example with the default step==6, .PP .Vb 4 \& 24 23 innermost ring 6 \& 25 22 next ring 12 \& 10 next ring 18 \& 26 11 9 21 ... ringnum*step \& \& 27 12 3 2 8 20 38 \& \& 28 13 4 1 7 19 37 <\- Y=0 \& \& 29 14 5 6 18 36 \& \& 30 15 17 35 \& 16 \& 31 24 \& 32 33 \& \& ^ \& X=0 .Ve .PP X,Y positions are not integers, except on the axes. The innermost ring like N=1to6 above has points 1 unit apart. Subsequent rings are a unit chord or unit radial, whichever ensures no overlap. .PP .Vb 2 \& step <= 6 unit spacing radially \& step >= 6 unit chords around the rings .Ve .PP For step=6 the two spacings are the same. Unit radial spacing ensures the X axis points N=1,7,19,37,etc shown above are 1 unit apart. Unit chord spacing ensures adjacent points such as N=7,8,0,etc don't overlap. .PP The layout is similar to the various spiral paths of corresponding step. For example step=6 is like the \f(CW\*(C`HexSpiral\*(C'\fR, but rounded out to circles instead of a hexagonal grid. Similarly step=4 the \f(CW\*(C`DiamondSpiral\*(C'\fR or step=8 the \f(CW\*(C`SquareSpiral\*(C'\fR. .PP The step parameter is also similar to the \f(CW\*(C`PyramidRows\*(C'\fR with the rows stretched around circles, but \f(CW\*(C`PyramidRows\*(C'\fR starts from a 1\-wide initial row whereas for \f(CW\*(C`MultipleRings\*(C'\fR here the first is \*(L"step\*(R" many. .SS "X Axis" .IX Subsection "X Axis" The starting Nring=1,7,19,37 etc on the X axis for the default step=6 is 6*d*(d\-1)/2 + 1, counting the innermost ring as d=1. In general Nring is a multiple of the triangular numbers d*(d\-1)/2, plus 1, .IX Xref "Triangular numbers" .PP .Vb 1 \& Nring = step*d*(d\-1)/2 + 1 .Ve .PP This is the centred polygonal numbers, being the cumulative count of points making concentric polygons or rings in the style of this path. .IX Xref "Centred polygonal numbers" .PP Straight line radials further around arise from adding multiples of d, so for example in step=6 shown above the line N=3,11,25,etc is Nring + 2*d. Multiples k*d with k>=step give lines which are in between the base ones from the innermost ring. .SS "Step 1" .IX Subsection "Step 1" For step=1 the first ring is 1 point and each subsequent ring has 1 further point. .PP .Vb 5 \& 24 \& 23 \& 18 12 17 \& 25 8 \& 13 5 \& \& 19 9 3 1 2 4 7 11 16 22 <\- Y=0 \& \& 14 6 \& 26 10 \& 20 15 21 \& 28 \& 27 \& \& ^ \& \-5 \-4 \-3 \-2\-1 X=0 1 2 3 4 5 6 .Ve .PP The rings are .PP .Vb 9 \& polygon radius N values \& \-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\-\-\- \& single point 0 1 \& two points 1 2, 3 \& triangle 2 4, 5, 6 \& square 3 7, 8, 9,10 \& pentagon 4 11,12,13,14,15 \& hexagon 5 16,17,18,19,20,21 \& etc .Ve .PP The X axis as described above is the triangular numbers plus 1, ie. k*(k+1)/2 + 1. .SS "Step 2" .IX Subsection "Step 2" For step=2 the arrangement is roughly .PP .Vb 5 \& 34 \& 35 33 \& 24 15 23 \& 36 25 22 32 \& 16 9 4 8 14 \& \& 37 26 17 10 5 2 1 3 7 13 21 31 \& \& 18 11 6 12 20 \& 38 27 30 42 \& 28 19 29 \& 39 41 \& 40 .Ve .PP The pattern is similar to the \f(CW\*(C`SacksSpiral\*(C'\fR (see Math::PlanePath::SacksSpiral). In \f(CW\*(C`SacksSpiral\*(C'\fR each spiral loop is 2 more points than the previous the same as here, but the positioning differs. Here the X axis is the pronic numbers and the squares are to the left, whereas in \f(CW\*(C`SacksSpiral\*(C'\fR rotated around to squares on X axis and pronics to the left. .SS "Ring Shape" .IX Subsection "Ring Shape" Option \f(CW\*(C`ring_shape => \*(Aqpolygon\*(Aq\*(C'\fR puts the points on concentric polygons of \*(L"step\*(R" many sides, so each concentric polygon has 1 more point on each of its sides than the previous polygon. For example step=4 gives 4\-sided polygons, ie. diamonds, .PP .Vb 10 \& 16 \& / \e ring_shape=>\*(Aqpolygon\*(Aq, step=>4 \& 17 7 15 \& / / \e \e \& 18 8 2 6 14 \& / / / \e \e \e \& 19 9 3 1 5 13 \& \e \e \e / / / \& 20 10 4 12 24 \& \e \e / / \& 21 11 23 \& \e / \& 22 .Ve .PP The polygons are scaled to keep points 1 unit apart. For step>=6 this means 1 unit apart sideways. step=6 is in fact a honeycomb grid where each points is 1 away from all six of its neighbours. .PP For step=3, 4 and 5 the polygon sides are 1 apart radially, as measured in the centre of each side. This makes points a little more than 1 apart along the sides. Squeezing them up to make the closest points exactly 1 apart is possible, but may require iterating a square root for each ring. step=3 squeezed down would in fact become a variable spacing with successively four close then one wider. .PP For step=2 and step=1 in the current code the default circle shape is used. Should that change? Is there a polygon style with 2 sides or 1 side? .PP The polygon layout is only a little different from a circle, but it lines up points on the sides and that might help show a structure for some sets of points plotted on the path. .SS "Step 3 Pentagonals" .IX Subsection "Step 3 Pentagonals" For step=3 the pentagonal numbers 1,5,12,22,etc, P(k) = (3k\-1)*k/2, are a radial going up to the left, and the second pentagonal numbers 2,7,15,26, S(k) = (3k+1)*k/2 are a radial going down to the left, respectively 1/3 and 2/3 the way around the circles. .PP As described in \*(L"Step 3 Pentagonals\*(R" in Math::PlanePath::PyramidRows, those P(k) and preceding P(k)\-1, P(k)\-2, and S(k) and preceding S(k)\-1, S(k)\-2 are all composites, so plotting the primes on a step=3 \f(CW\*(C`MultipleRings\*(C'\fR has two radial gaps where there's no primes. .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::MultipleRings\->new (step => $integer)""" 4 .el .IP "\f(CW$path = Math::PlanePath::MultipleRings\->new (step => $integer)\fR" 4 .IX Item "$path = Math::PlanePath::MultipleRings->new (step => $integer)" .PD 0 .ie n .IP """$path = Math::PlanePath::MultipleRings\->new (step => $integer, ring_shape => $str)""" 4 .el .IP "\f(CW$path = Math::PlanePath::MultipleRings\->new (step => $integer, ring_shape => $str)\fR" 4 .IX Item "$path = Math::PlanePath::MultipleRings->new (step => $integer, ring_shape => $str)" .PD Create and return a new path object. .Sp The \f(CW\*(C`step\*(C'\fR parameter controls how many points are added in each circle. It defaults to 6 which is an arbitrary choice and the suggestion is to always pass in a desired count. .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 >= 1\*(C'\fR and fractions give positions on the rings in between the integer points. For \f(CW\*(C`$n < 1\*(C'\fR the return is an empty list since points begin at 1. .Sp Fractional \f(CW$n\fR currently ends up on the circle arc between the integer points. Would straight line chords between them be better, reflecting the unit spacing of the points? Neither seems particularly important. .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 points 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. .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 "N to X,Y \- Circle" .IX Subsection "N to X,Y - Circle" As per above, each ring begins at .PP .Vb 1 \& Nring = step*d*(d\-1)/2 + 1 .Ve .PP This can be inverted to get the ring number d for a given N, and then subtract Nring for a remainder into the ring. (N\-1)/step in the formula effectively converts into triangular number style. .PP .Vb 2 \& d = floor((sqrt(8*(N\-1)/step + 1) + 1) / 2) \& Nrem = N \- Nring .Ve .PP Rings are sized so that points are spaced 1 unit apart. There are three cases, .PP .Vb 3 \& circle, step<=6 unit radially on X axis \& polygon, step<=6 unit radially on sides centre \& step>=7 unit chord between points .Ve .PP For the circle shape the integer points are on a circle and fractional N is on a straight line between those integer points. This means it's a polygon too, but one with ever more sides whereas ring_shape=polygon is a fixed \&\*(L"step\*(R" many sides. .PP .Vb 2 \& circle numsides = d*step \& polygon numsides = step .Ve .PP The radial distance to a polygon corner is calculated as .PP .Vb 6 \& base varying with d \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& circle, step<=6 0.5/sin(pi/step) + d\-1 \& polygon, step<=6 0.5/sin(pi/step) + (d\-1)/cos(pi/step) \& circle, step>=7 0 + 0.5/sin(pi/(d*step)) \& polygon, step>=7 0 + d * 0.5/sin(pi/step) .Ve .PP The step<=6 cases are an initial polygon of \*(L"step\*(R" many unit sides, then unit spacing d\-1 for circle, or for polygon (d\-1)/cos(pi/step) which is bigger and ensures the middle of the sides have unit spacing radially. .PP The 0.5/sin(pi/step) for radius of a unit sided polygon arises from .PP .Vb 4 \& r _\|_\|_\-\-\-* \& _\|_\|_\-\-\- | 1/2 = half the polygon side \& _\|_\|_\-\-\- alpha | \& o\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& \& alpha = (2pi/numsides) / 2 = pi/numsides \& sin(alpha) = (1/2) / base_r \& r = 0.5 / sin(pi/numsides) .Ve .PP The angle theta to a polygon vertex is simply a full circle divided by numsides. .PP .Vb 5 \& side = circle Nrem \& polygon floor(Nrem / step) \& theta = side * (2pi / numsides) \& vertex X = r * cos(theta) \& Y = r * sin(theta) \& \& next_theta = (side+1) * (2pi / numsides) \& next_vertex X = r * cos(next_theta) \& Y = r * sin(next_theta) \& \& frac into side \& f = circle frac(Nrem) = Nrem modulo 1 \& polygon Nrem \- side*d = Nrem modulo d \& \& X = vertex_X + f * (next_vertex_X \- vertex_X) \& Y = vertex_Y + f * (next_vertex_Y \- vertex_Y) .Ve .PP If Nrem is an integer for circle, or multiple of d for polygon, then the vertex X,Y is the final X,Y, otherwise a fractional distance between the vertex X,Y and next vertex X,Y. .PP For a few cases X or Y are exact integers. Special case code for these cases can ensure floating point rounding of pi doesn't give small offsets from integers. .PP For step=6 the base r is r=1 exactly since the innermost ring is a little hexagon. This means for the circle step=6 case the points on the X axis (positive and negative) are all integers X=1,2,3,etc. .PP .Vb 7 \& P\-\-\-\-\-P \& / 1 / \e 1 <\-\- innermost points 1 apart \& / / \e \& P o\-\-\-\-\-P <\-\- base_r = 1 \& \e 1 / \& \e / \& P\-\-\-\-\-P .Ve .PP If theta=pi, which is when 2*Nrem==d*step, then the point is on the negative X axis. Returning Y=0 exactly for that avoids sin(pi) giving some small non-zero due to rounding. .PP If theta=pi/2 or theta=3pi/2, which is 4*Nrem==d*step or 4*Nrem==3*d*step, then N is on the positive or negative Y axis (respectively). Returning X=0 exactly avoids cos(pi/2) or cos(3pi/2) giving some small non-zero. .PP Points on the negative X axis points occur when the step is even. Points on the Y axis points occur when the step is a multiple of 4. .PP If theta=pi/4, 3*pi/4, 5*pi/4 or 7*pi/4, which is 8*Nrem==d*step, 3*d*step, 5*d*step or 7*d*step then the points are on the 45\-degree lines X=Y or X=\-Y. The current code doesn't try to ensure X==Y in these cases. The values are not integers and floating point rounding might mean sin(pi/4)!=cos(pi/4) resulting in X!=Y. .SS "N to RSquared \- Step 1" .IX Subsection "N to RSquared - Step 1" For step=1 the rings are point, line, triangle, square, pentagon, etc, with vertices at radius=numsides\-1. For fractional N the triangle, square and hexagon cases are quadratics in the fraction part, allowing exact values from \f(CW\*(C`n_to_rsquared()\*(C'\fR. .PP .Vb 5 \& Ring R^2 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\- \& triangle 4 <= N < 7 4 \- 12*f*(1\-f) \& square 7 <= N < 11 9 \- 18*f*(1\-f) \& hexagon 16 <= N < 22 25 \- 25*f*(1\-f) \& \& f = N \- int(N) fractional part of N .Ve .PP For example for the square at N=7.5 have f=0.5 and R^2=4.5 exactly. These quadratics arise because sine of 2pi/3, 2pi/4 and 2pi/6 are square roots, which on squaring up in R^2=X^2+Y^2 become integer factors for the fraction f along the polygon side. .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 5 \& A005448 A001844 A005891 A003215 A069099 3 to 7 \& A016754 A060544 A062786 A069125 A003154 8 to 12 \& A069126 A069127 A069128 A069129 A069130 13 to 17 \& A069131 A069132 A069133 18 to 20 \& N on X axis of step=k, being the centred pentagonals \& \& step=1 \& A002024 Radius+1, runs of n repeated n times \& \& step=8 \& A090915 permutation N at X,\-Y, mirror across X axis .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Math::PlanePath, Math::PlanePath::SacksSpiral, Math::PlanePath::TheodorusSpiral, Math::PlanePath::PixelRings .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 .