NAME
Math::PlanePath::SierpinskiArrowheadCentres  selfsimilar triangular path traversal
SYNOPSIS
use Math::PlanePath::SierpinskiArrowheadCentres;
my $path = Math::PlanePath::SierpinskiArrowheadCentres>new;
my ($x, $y) = $path>n_to_xy (123);
DESCRIPTION
This path is variation on Sierpinski's curve from
Waclaw Sierpinski, "Sur une Courbe Dont Tout Point est un Point de Ramification", Comptes Rendus Hebdomadaires des Séances de l'Académie des Sciences, volume 160, JanuaryJune 1915, pages 302305. http://gallica.bnf.fr/ark:/12148/bpt6k31131/f302.image.langEN
The path here takes the centres of each triangle represented by the arrowhead segments. The points visited are the same as the SierpinskiTriangle
path, but traversing in a connected sequence (rather than across rows).
... ...
/ /
. 30 . . . . . 65 . ...
/ \ /
2829 . . . . . . 66 68 9
\ \ /
27 . . . . . . . 67 8
\
2625 191817 151413 7
/ \ \ / /
24 . 20 . 16 . 12 6
\ / /
23 21 . . 1011 5
\ / \
22 . . . 9 4
/
4 5 6 8 3
\ \ /
3 . 7 2
\
2 1 1
/
0 < Y=0
9 8 7 6 5 4 3 2 1 X=0 1 2 3 4 5 6 7
The base figure is the N=0 to N=2 shape. It's repeated up in mirror image as N=3 to N=6 then rotated across as N=6 to N=9. At the next level the same is done with N=0 to N=8 as the base, then N=9 to N=17 up mirrored, and N=18 to N=26 across, etc.
The X,Y coordinates are on a triangular lattice using every second integer X, per "Triangular Lattice" in Math::PlanePath.
The base pattern is a triangle like
...
\ / \ /
\ 2 / \ 1 /
\ / \ /
.   .
\ /
\ 0 /
\ /
.
Higher levels replicate this within the triangles 0,1,2 but the middle is not traversed. The result is the familiar Sierpinski triangle by connected steps of either 2 across or 1 diagonal.
* * * * * * * * * * * * * * * *
* * * * * * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * *
* * * *
* *
* * * * * * * *
* * * *
* * * *
* *
* * * *
* *
* *
*
See the SierpinskiTriangle
path to traverse by rows instead.
Level Ranges
Counting the N=0,1,2 part as level 1, each replication level goes from
Nstart = 0
Nlevel = 3^level  1 inclusive
For example level 2 from N=0 to N=3^21=9. Each level doubles in size,
0 <= Y <= 2^level  1
 (2^level  1) <= X <= 2^level  1
The Nlevel position is alternately on the right or left,
Xlevel = / 2^level  1 if level even
\  2^level + 1 if level odd
The Y axis ie. X=0, is crossed just after N=1,5,17,etc which is is 2/3 through the level, which is after two replications of the previous level,
Ncross = 2/3 * 3^level  1
= 2 * 3^(level1)  1
Align Parameter
An optional align
parameter controls how the points are arranged relative to the Y axis. The default shown above is "triangular". The choices are the same as for the SierpinskiTriangle
path.
"right" means points to the right of the axis, packed next to each other and so using an eighth of the plane.
align => "right"
 
7  2625 191817 151413
 /  / /
6  24 20 16 12
  / /
5  23 21 1011
 / 
4  22 9
 /
3  456 8
  /
2  3 7
 
1  21
 /
Y=0  0
+
X=0 1 2 3 4 5 6 7
"left" is similar but skewed to the left of the Y axis, ie. into negative X.
align => "left"
\ 
2625 191817 151413  7
 \ \   
24 20 16 12  6
\   
23 21 1011  5
\  \ 
22 9  4
 
456 8  3
\ \  
3 7  2
\ 
21  1
 
0  Y=0
+
7 6 5 4 3 2 1 X=0
"diagonal" puts rows on diagonals down from the Y axis to the X axis. This uses the whole of the first quadrant, with gaps.
align => "diagonal"
 
7  26
 \
6  2425
 
5  23 19
  \
4  222120 18
 \
3  4 17
 \ 
2  3 5 1615
  \ \
1  2 6 10 14
 \  \ \
Y=0  01 789 111213
+
X=0 1 2 3 4 5 6 7
These diagonals visit all points X,Y where X and Y written in binary have no 1bits in the same places, ie. where X bitand Y = 0. This is the same as the SierpinskiTriangle
with align=diagonal.
FUNCTIONS
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::SierpinskiArrowheadCentres>new ()
$path = Math::PlanePath::SierpinskiArrowheadCentres>new (align => $str)

Create and return a new arrowhead path object.
align
is a string, one of the following as described above."triangular" the default "right" "left" "diagonal"
($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.If
$n
is not an integer then the return is on a straight line between the integer points.
Level Methods
FORMULAS
N to X,Y
The align="diagonal" style is the most convenient to calculate. Each ternary digit of N becomes a bit of X and Y.
ternary digits of N, high to low
xbit = state_to_xbit[state+digit]
ybit = state_to_ybit[state+digit]
state = next_state[state+digit]
There's a total of 6 states which are the permutations of 0,1,2 in the three triangular parts. The states are in pairs as forward and reverse, but that has no particular significance. Numbering the states by "3"s allows the digit 0,1,2 to be added to make an index into tables for X,Y bit and next state.
state=0 state=3
++ ++
^ 2   \ 0  
 \    \  
 \    v  
+ +
 ^    
 0  1   0  1 
>  <v 
++ ++
state=6 state=9
++ ++
     
 1    1  
>  < 
+ +
^ \ 2   ^ 
0  \   2  \0 
  v  v  \ 
++ ++
state=12 state=15
++ ++
 0   ^  
    2  
v     
+ +
\ 1   ^ 1  
 \  2   \  0 
 v >  \ <
++ ++
The initial state is 0 if an even number of ternary digits, or 6 if odd. In the samples above it can be seen for example that N=0 to N=8 goes upwards as per state 0, whereas N=0 to N=2 goes across as per state 6.
Having calculated an X,Y in align="diagonal" style it can be mapped to the other alignments by
align coordinates from diagonal X,Y
 
triangular XY, X+Y
right X, X+Y
left Y, X+Y
N to dX,dY
For fractional N the direction of the curve towards the N+1 point can be found from the least significant digit 0 or 1 (ie. a non2 digit) and the state at that point.
This works because if the least significant ternary digit of N is a 2 then the direction of the curve is determined by the next level up, and so on for all trailing 2s until reaching a non2 digit.
If N is all 2s then the direction should be reckoned from an initial 0 digit above them, which means the opposite 6 or 0 of the initial state.
Rectangle to N Range
An easy overestimate of the range can be had from inverting the Nlevel formulas in "Level Ranges" above.
level = floor(log2(Ymax)) + 1
Nmax = 3^level  1
For example Y=5, level=floor(log2(11))+1=3, so Nmax=3^31=26, which is the left end of the Y=7 row, ie. rounded up to the end of the Y=4 to Y=7 replication.
SEE ALSO
Math::PlanePath, Math::PlanePath::SierpinskiArrowhead, Math::PlanePath::SierpinskiTriangle
HOME PAGE
http://user42.tuxfamily.org/mathplanepath/index.html
LICENSE
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde
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/>.