.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Math::PlanePath::KochSnowflakes 3pm" .TH Math::PlanePath::KochSnowflakes 3pm "2014-08-27" "perl v5.20.1" "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::KochSnowflakes \-\- Koch snowflakes as concentric rings .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Math::PlanePath::KochSnowflakes; \& my $path = Math::PlanePath::KochSnowflakes\->new; \& my ($x, $y) = $path\->n_to_xy (123); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This path traces out concentric integer versions of the Koch snowflake at successively greater iteration levels. .PP .Vb 10 \& 48 6 \& / \e \& 50\-\-\-\-49 47\-\-\-\-46 5 \& \e / \& 54 51 45 42 4 \& / \e / \e / \e \& 56\-\-\-\-55 53\-\-\-\-52 44\-\-\-\-43 41\-\-\-\-40 3 \& \e / \& 57 12 39 2 \& / / \e \e \& 58\-\-\-\-59 14\-\-\-\-13 11\-\-\-\-10 37\-\-\-\-38 1 \& \e \e 3 / / \& 60 15 1\-\-\-\-2 9 36 <\- Y=0 \& / \e \e \& 62\-\-\-\-61 4\-\-\-\- 5 7\-\-\-\- 8 35\-\-\-\-34 \-1 \& \e \e / / \& 63 6 33 \-2 \& \e \& 16\-\-\-\-17 19\-\-\-\-20 28\-\-\-\-29 31\-\-\-\-32 \-3 \& \e / \e / \e / \& 18 21 27 30 \-4 \& / \e \& 22\-\-\-\-23 25\-\-\-\-26 \-5 \& \e / \& 24 \-6 \& \& ^ \& \-9 \-8 \-7 \-6 \-5 \-4 \-3 \-2 \-1 X=0 1 2 3 4 5 6 7 8 9 .Ve .PP The initial figure is the triangle N=1,2,3 then for the next level each straight side expands to 3x longer and a notch like N=4 through N=8, .PP .Vb 3 \& *\-\-\-* becomes *\-\-\-* *\-\-\-* \& \e / \& * .Ve .PP The angle is maintained in each replacement, for example the segment N=5 to N=6 becomes N=20 to N=24 at the next level. .SS "Triangular Coordinates" .IX Subsection "Triangular Coordinates" The X,Y coordinates are arranged as integers on a square grid per \&\*(L"Triangular Lattice\*(R" in Math::PlanePath, except the Y coordinates of the innermost triangle which is .PP .Vb 9 \& N=3 X=0, Y=+2/3 \& * \& / \e \& / \e \& / \e \& / o \e \& / \e \& N=1 *\-\-\-\-\-\-\-\-\-\-\-* N=2 \& X=\-1, Y=\-1/3 X=1, Y=\-1/3 .Ve .PP These values are not integers, but they're consistent with the centring and scaling of the higher levels. If all-integer is desired then rounding gives Y=0 or Y=1 and doesn't overlap the subsequent points. .SS "Level Ranges" .IX Subsection "Level Ranges" Counting the innermost triangle as level 0, each ring is .PP .Vb 2 \& Nstart = 4^level \& length = 3*4^level many points .Ve .PP For example the outer ring shown above is level 2 starting N=4^2=16 and having length=3*4^2=48 points (through to N=63 inclusive). .PP The X range at a given level is the initial triangle baseline iterated out. Each level expands the sides by a factor of 3 so .PP .Vb 2 \& Xlo = \-(3^level) \& Xhi = +(3^level) .Ve .PP For example level 2 above runs from X=\-9 to X=+9. The Y range is the points N=6 and N=12 iterated out. Ylo in level 0 since there's no downward notch on that innermost triangle. .PP .Vb 3 \& Ylo = / \-(2/3)*3^level if level >= 1 \& \e \-1/3 if level == 0 \& Yhi = +(2/3)*3^level .Ve .PP Notice that for each level the extents grow by a factor of 3 but the notch introduced in each segment is not big enough to go past the corner positions. They can equal the extents horizontally, for example in level 1 N=14 is at X=\-3 the same as the corner N=4, and on the right N=10 at X=+3 the same as N=8, but they don't go past. .PP The snowflake is an example of a fractal curve with ever finer structure. The code here can be used for that by going from N=Nstart to N=Nstart+length\-1 and scaling X/3^level Y/3^level to give a 2\-wide 1\-high figure of desired fineness. See \fIexamples/koch\-svg.pl\fR in the Math-PlanePath sources for a complete program doing that as an \s-1SVG\s0 image file. .SS "Area" .IX Subsection "Area" The area of the snowflake at a given level can be calculated from the area under the Koch curve per \*(L"Area\*(R" in Math::PlanePath::KochCurve which is the 3 sides, and the central triangle .PP .Vb 5 \& * ^ Yhi \& / \e | height = 3^level \& / \e | \& / \e | \& *\-\-\-\-\-\-\-* v \& \& <\-\-\-\-\-\-\-> width = 3^level \- (\- 3^level) = 2*3^level \& Xlo Xhi \& \& triangle_area = width*height/2 = 9^level \& \& snowflake_area[level] = triangle_area[level] + 3*curve_area[level] \& = 9^level + 3*(9^level \- 4^level)/5 \& = (8*9^level \- 3*4^level) / 5 .Ve .PP If the snowflake is conceived as a fractal of fixed initial triangle size and ever-smaller notches then the area is divided by that central triangle area 9^level, .PP .Vb 3 \& unit_snowflake[level] = snowflake_area[level] / 9^level \& = (8 \- 3*(4/9)^level) / 5 \& \-> 8/5 as level \-> infinity .Ve .PP Which is the well-known 8/5 * initial triangle area for the fractal snowflake. .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::KochSnowflakes\->new ()""" 4 .el .IP "\f(CW$path = Math::PlanePath::KochSnowflakes\->new ()\fR" 4 .IX Item "$path = Math::PlanePath::KochSnowflakes->new ()" Create and return a new path object. .SS "Level Methods" .IX Subsection "Level Methods" .ie n .IP """($n_lo, $n_hi) = $path\->level_to_n_range($level)""" 4 .el .IP "\f(CW($n_lo, $n_hi) = $path\->level_to_n_range($level)\fR" 4 .IX Item "($n_lo, $n_hi) = $path->level_to_n_range($level)" Return per \*(L"Level Ranges\*(R" above, .Sp .Vb 2 \& (4**$level, \& 4**($level+1) \- 1) .Ve .SH "FORMULAS" .IX Header "FORMULAS" .SS "Rectangle to N Range" .IX Subsection "Rectangle to N Range" As noted in \*(L"Level Ranges\*(R" above, for a given level .PP .Vb 2 \& \-(3^level) <= X <= 3^level \& \-(2/3)*(3^level) <= Y <= (2/3)*(3^level) .Ve .PP So the maximum X,Y in a rectangle gives .PP .Vb 1 \& level = ceil(log3(max(abs(x1), abs(x2), abs(y1)*3/2, abs(y2)*3/2))) .Ve .PP and the last point in that level is .PP .Vb 1 \& Nlevel = 4^(level+1) \- 1 .Ve .PP Using this as an N range is an over-estimate, but an easy calculation. It's not too difficult to trace down for an exact range .SH "OEIS" .IX Header "OEIS" Entries in Sloane's Online Encyclopedia of Integer Sequences related to the Koch snowflake include the following. See \&\*(L"\s-1OEIS\*(R"\s0 in Math::PlanePath::KochCurve for entries related to a single Koch side. .Sp .RS 4 (etc) .RE .PP .Vb 3 \& A164346 number of points in ring n, being 3*4^n \& A178789 number of acute angles in ring n, 4^n + 2 \& A002446 number of obtuse angles in ring n, 2*4^n \- 2 .Ve .PP The acute angles are those of +/\-120 degrees and the obtuse ones +/\-240 degrees. Eg. in the outer ring=2 shown above the acute angles are at N=18, 22, 24, 26, etc. The angles are all either acute or obtuse, so .PP .Vb 1 \& A178789 + A002446 = A164346 .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Math::PlanePath, Math::PlanePath::KochCurve, Math::PlanePath::KochPeaks .PP Math::PlanePath::QuadricIslands .SH "HOME PAGE" .IX Header "HOME PAGE" .SH "LICENSE" .IX Header "LICENSE" Copyright 2011, 2012, 2013, 2014 Kevin Ryde .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 .