NAME
Math::PlanePath::R5DragonMidpoint  R5 dragon curve midpoints
SYNOPSIS
use Math::PlanePath::R5DragonMidpoint;
my $path = Math::PlanePath::R5DragonMidpoint>new;
my ($x, $y) = $path>n_to_xy (123);
DESCRIPTION
This is midpoints of the R5 dragon curve by Jorg Arndt,
3130 11
 
32 29 10
 
5150 353433 282726 9
   
52 49 363738 232425 8
   
555453 484746 414039 22 7
   
565758 6364 45 42 192021 6
     
8180 59 62 65 4443 181716 1110 5
       
82 79 6061 666768 15 12 9 4
     
..83 787776 717069 1413 8 7 6 3
  
75 72 3 4 5 2
  
7473 2 1

0 1 < Y=0
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
10 9 8 7 6 5 4 3 2 1 X=0 1 2 3
The points are the middle of each edge of the R5DragonCurve
, rotated 45 degrees, shrunk by sqrt(2). and shifted to the origin.
*11* *7* R5DragonCurve
    and its midpoints
12 10 8 6
   
*17*13*9*5*
   
18 16 14 4
   
..* *15* *3*

2

+1*
Arms
Multiple copies of the curve can be selected, each advancing successively. Like the main R5DragonCurve
this midpoint curve covers 1/4 of the plane and 4 arms rotated by 0, 90, 180, 270 degrees mesh together perfectly. With 4 arms all integer X,Y points are visited.
arms => 4
begins as follows. N=0,4,8,12,16,etc is the first arm (the same shape as the plain curve above), then N=1,5,9,13,17 the second, N=2,6,10,14 the third, etc.
arms=>4 7680... 6

726864 4440 5
  
2521 60 48 36 4
    
29 17 5652 322824 7579 3
    
413733 13 9 5 121620 71 83 2
    
454953 6 2 1 8 596367 ... 1
   
... 656157 10 3 0 4 555147 < Y=0
    
81 69 221814 71115 353943 1
    
7773 263034 5458 19 31 2
    
38 50 62 2327 3
  
4246 667074 4

...8278 5
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
6 5 4 3 2 1 X=0 1 2 3 4 5
FUNCTIONS
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::R5DragonMidpoint>new ()

Create and return a new path object.
($x,$y) = $path>n_to_xy ($n)

Return the X,Y coordinates of point number
$n
on the path. Points begin at 0 and if$n < 0
then the return is an empty list.Fractional positions give an X,Y position along a straight line between the integer positions.
$n = $path>n_start()

Return 0, the first N in the path.
Level Methods
($n_lo, $n_hi) = $path>level_to_n_range($level)

Return
(0, 5**$level  1)
, or for multiple arms return(0, $arms * 5**$level  1)
.There are 5^level segments comprising the curve, or arms*5^level when multiple arms, numbered starting from 0.
FORMULAS
X,Y to N
An X,Y point can be turned into N by dividing out digits of a complex base 1+2i. At each step the low base5 digit is formed from X,Y and an adjustment applied to move X,Y to a multiple of 1+2i ready to divide out.
A 10x10 table is used for the digit and adjustments, indexed by Xmod10 and Ymod10. There's probably an a*X+b*Y mod 5 or mod 20 for a smaller table. But in any case once the adjustment is found the result is
Ndigit = digit_table[X mod 10, Y mod 10] # low to high
Xm = X + Xadj_table [X mod 10, Y mod 10]
Ym = Y + Yadj_table [X mod 10, Y mod 10]
new X,Y = (Xm,Ym) / (1+2i)
= (Xm,Ym) * (12i) / 5
= ((Xm+2*Ym)/5, (Ym2*Xm)/5)
These X,Y reductions eventually reach one of the starting points for the four arms
X,Y endpoint Arm +++
   2  1  Y=1
0, 0 0 +++
0, 1 1  3  0  Y=0
1, 1 2 +++
1, 0 3 X=1 X=0
For arms 1 and 3 the digits must be flipped 4digit, so 0,1,2,3,4 > 4,3,2,1,0. The arm number and hence whether this flip is needed is not known until reaching the endpoint.
if arm odd
then N = 5^numdigits  1  N
If only some of the arms are of interest then reaching one of the other arm numbers means the original X,Y was outside the desired curve.
SEE ALSO
Math::PlanePath, Math::PlanePath::R5DragonCurve
Math::PlanePath::DragonMidpoint, Math::PlanePath::TerdragonMidpoint
HOME PAGE
http://user42.tuxfamily.org/mathplanepath/index.html
LICENSE
Copyright 2012, 2013, 2014, 2015, 2016, 2017 Kevin Ryde
This file is part of MathPlanePath.
MathPlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
MathPlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with MathPlanePath. If not, see <http://www.gnu.org/licenses/>.