.\" 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::TerdragonMidpoint 3pm" .TH Math::PlanePath::TerdragonMidpoint 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::TerdragonMidpoint \-\- dragon curve midpoints .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Math::PlanePath::TerdragonMidpoint; \& my $path = Math::PlanePath::TerdragonMidpoint\->new; \& my ($x, $y) = $path\->n_to_xy (123); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is midpoints of an integer version of the terdragon curve by Davis and Knuth. .IX Xref "Davis Knuth, Donald" .PP .Vb 10 \& 30\-\-\-\-29\-\-\-\-28\-\-\-\-27 13 \& \e / \& 31 26 12 \& \e / \& 36\-\-\-\-35\-\-\-\-34\-\-\-\-33\-\-\-\-32 25 11 \& \e / \& 37 41 24 10 \& \e / \e / \& 38 40 42 23\-\-\-\-22\-\-\-\-21 9 \& \e / \e / \& 39 43 20 8 \& \e / \& 48\-\-\-\-47\-\-\-\-46\-\-\-\-45\-\-\-\-44 19 12\-\-\-\-11\-\-\-\-10\-\-\-\-\-9 7 \& \e / \e / \& 49 18 13 8 6 \& \e / \e / \& ...\-\-\-50 17\-\-\-\-16\-\-\-\-15\-\-\-\-14 7 5 \& / \& 6 4 \& / \& 5\-\-\-\-\-4\-\-\-\-\-3 3 \& / \& 2 2 \& / \& 1 1 \& / \& 0 <\- Y=0 \& \& ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \& \-12\-11\-10 \-9 \-8 \-7 \-6 \-5 \-4 \-3 \-2 \-1 X=0 1 2 3 4 5 ... .Ve .PP The points are the middle of each edge of a double-size \f(CW\*(C`TerdragonCurve\*(C'\fR. .PP .Vb 10 \& ... \& \e \& 6 \-\-\-\-\-8\-\-\-\-\- double size \& \e TerdragonCurve \& \e giving midpoints \& 5 7 \& \e \& \e \& 4 \-\-\-\-\-6\-\-\-\- _ \& \e / \e \& \e / \e \& 3 5 4 3 \& \e / \e \& \e_/ \e \& 2 _\-\-\-\-2\-\-\-\-\- \& \e \& \e \& 1 1 \& \e \& \e \& Y=0 \-> +\-\-\-\-\-0\-\-\-\-\-. \& \& ^ \& X=0 1 2 3 4 5 6 .Ve .PP For example in the \f(CW\*(C`TerdragonCurve\*(C'\fR N=3 to N=4 is X=3,Y=1 to X=2,Y=2 and that's doubled out here to X=6,Y=2 and X=4,Y=4 then the midpoint of those positions is X=5,Y=3 for N=3 in the \f(CW\*(C`TerdragonMidpoint\*(C'\fR. .PP The result is integer X,Y coordinates on every second point per \&\*(L"Triangular Lattice\*(R" in Math::PlanePath, but visiting only 3 of every 4 such triangular points, which in turn is 3 of 8 all integer X,Y points. The points used are a pattern of alternate rows with 1 of 2 points and 1 of 4 points. For example the Y=7 row is 1 of 2 and the Y=8 row is 1 of 4. Notice the pattern is the same when turned by 60 degrees. .PP .Vb 10 \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * \& * * * * * * * * * * \& * * * * * * * * * * * * * * * * * * * * .Ve .SS "Arms" .IX Subsection "Arms" Multiple copies of the curve can be selected, each advancing successively. Like the main \f(CW\*(C`TerdragonCurve\*(C'\fR the midpoint curve covers 1/6 of the plane and 6 arms rotated by 60, 120, 180, 240 and 300 degrees mesh together perfectly. With 6 arms all the alternating \*(L"1of2\*(R" and \*(L"1of4\*(R" points described above are visited. .PP \&\f(CW\*(C`arms => 6\*(C'\fR begins as follows. N=0,6,12,18,etc is the first arm (like the single curve above), then N=1,7,13,19 the second copy rotated 60 degrees, N=2,8,14,20 the third rotated 120, etc. .PP .Vb 10 \& arms=>6 ... \& / \& ... 42 \& \e / \& 43 19 36 \& \e / \e / \& 37 25 13 30\-\-\-\-24\-\-\-\-18 \& \e / \e / \& 31 7 12 \& \e / \& 20\-\-\-\-14\-\-\-\-\-8\-\-\-\-\-2 1 6 35\-\-\-\-41\-\-\-\-47\-.. \& \e / \e \& 26 3 . 0 29 \& \e / \e \& ..\-44\-\-\-\-38\-\-\-\-32 9 4 5\-\-\-\-11\-\-\-\-17\-\-\-\-23 \& / \e \& 15 10 34 \& / \e / \e \& 21\-\-\-\-27\-\-\-\-33 16 28 40 \& / \e / \e \& 39 22 46 \& / \e \& 45 ... \& / \& ... .Ve .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::TerdragonMidpoint\->new ()""" 4 .el .IP "\f(CW$path = Math::PlanePath::TerdragonMidpoint\->new ()\fR" 4 .IX Item "$path = Math::PlanePath::TerdragonMidpoint->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. Points begin at 0 and if \f(CW\*(C`$n < 0\*(C'\fR then the return is an empty list. .Sp Fractional positions give an X,Y position along a straight line between the integer positions. .ie n .IP """$n = $path\->n_start()""" 4 .el .IP "\f(CW$n = $path\->n_start()\fR" 4 .IX Item "$n = $path->n_start()" Return 0, the first N in the path. .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 \f(CW\*(C`(0, 3**$level \- 1)\*(C'\fR, or for multiple arms return \f(CW\*(C`(0, $arms * 3**$level \- 1)\*(C'\fR. .Sp There are 3^level segments comprising the terdragon, or arms*3^level when multiple arms, numbered starting from 0. .SH "FORMULAS" .IX Header "FORMULAS" .SS "X,Y to N" .IX Subsection "X,Y to N" An X,Y point can be turned into N by dividing out digits of a complex base b=w+1 where .PP .Vb 7 \& w = 1/2 + i * sqrt(3)/2 w^2 w \& = 6th root of unity \e / \& \e / \& w^3=\-1 \-\-\-\-\-o\-\-\-\-\-\- w^0=1 \& / \e \& / \e \& w^4 w^5 .Ve .PP At each step the low ternary digit is formed from X,Y and an adjustment applied to move X,Y onto a multiple of w+1 ready to divide out w+1. .PP In the N points above it can be seen that each group of three N values make a straight line, such as N=0,1,2, or N=3,4,5 etc. The adjustment moves the two ends N=0mod3 or N=2mod3 to the centre N=1mod3. The centre N=1mod3 position is always a multiple of w+1. .PP The angles and positions for the N triples follow a 12\-point pattern as follows, where each / \e or \- is a point on the path (any arm). .PP .Vb 10 \& \e / / \e / / \e / / \e / / \e \& \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \& / \e / / \e / / \e / / \e / \& \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \& \e / / \e / / \e / / \e / / \e \& \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \& / \e / / \e / / \e / / \e / \& \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \& \e / / \e / / \e / / \e / / \e \& \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \& / \e / / \e / / \e / / \e / \& \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \& \e / / \e / / \e / / \e / / \e \& \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \& / \e / / \e / / \e / / \e / \& \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \& \e / / \e / / \e / / \e / / \e \& \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \& / \e / / \e / / \e / / \e / \& \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \& \e / / \e / / \e / / \e / / \e \& \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \& / \e / / \e / / \e / / \e / \& \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e \- \- \- \e / \e .Ve .PP In the current code a 12x12 table is used, indexed by X mod 12 and Y mod 12. With Xadj and Yadj from there .PP .Vb 1 \& Ndigit = (X + 1) mod 3 # N digits low to high \& \& Xm = X + Xadj[X mod 12, Y mod 12] \& Ym = Y + Yadj[X mod 12, Y mod 12] \& \& new X,Y = (Xm,Ym) / (w+1) \& = (Xm,Ym) * (2\-w) / 3 \& = ((Xm+Ym)/2, (Ym\-(Xm/3))/2) .Ve .PP Is there a good aX+bY mod 12 or mod 24 for a smaller table? Maybe X+3Y like the digit? Taking C=(X\-Y)/2 in triangular coordinate style can reduce the table to 6x6. .PP Points not reached by the curve (ie. not the 3 of 4 triangular or 3 of 8 rectangular described above) can be detected with \f(CW\*(C`undef\*(C'\fR or suitably tagged entries in the adjustment table. .PP The X,Y reduction stops at the midpoint of the first triple of the originating arm. So X=3,Y=1 which is N=1 for the first arm, and that point rotated by 60,120,180,240,300 degrees for the others. If only some of the arms are of interest then reaching one of the others means the original X,Y was outside the desired region. .PP .Vb 8 \& Arm X,Y Endpoint \& \-\-\- \-\-\-\-\-\-\-\-\-\-\-\- \& 0 3,1 \& 1 0,2 \& 2 \-3,1 \& 3 \-3,\-1 \& 4 0,\-2 \& 5 3,\-1 .Ve .PP For the odd arms 1,3,5 each digit of N must be flipped 2\-digit so 0,1,2 becomes 2,1,0, .PP .Vb 2 \& if arm odd \& then N = 3**numdigits \- 1 \- N .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Math::PlanePath, Math::PlanePath::TerdragonCurve, Math::PlanePath::TerdragonRounded .PP Math::PlanePath::DragonMidpoint, Math::PlanePath::R5DragonMidpoint .SH "HOME PAGE" .IX Header "HOME PAGE" .SH "LICENSE" .IX Header "LICENSE" Copyright 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 .