NAME
Math::PlanePath::MathImageFlowsnake -- self-similar path traversal
SYNOPSIS
use Math::PlanePath::MathImageFlowsnake;
my $path = Math::PlanePath::MathImageFlowsnake->new;
my ($x, $y) = $path->n_to_xy (123);
DESCRIPTION
In progress. No xy_to_n
yet. And rect_to_n_range
is an under-estimate. A full range would be N=1e14 or more to cover Y from say -500 to +500, which is nearly past the accuracy of 53-bit floats ...
This path is an integer version of the flowsnake curve by William Gosper, making a self-similar traversal of the plane.
39----40----41 8
\ \
32----33----34 38----37 42 7
\ \ / /
31----30 35----36 43 47----48 6
/ \ \ \
28----29 17----16----15 44 46 49... 5
/ \ \ \ /
27 23----22 18----19 14 45 4
\ \ \ / /
26 24 21----20 13 11----10 3
\ / \ / /
25 4---- 5---- 6 12 9 2
\ \ /
3---- 2 7---- 8 1
/
0---- 1 y=0
x=-4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11
The points are spread out on every second X coordinate to make little triangles but staying in integer coordinates. It should be equilateral triangles, but on a square grid this comes out a little flatter.
The basic pattern is the seven points 0 to 6,
4---- 5---- 6
\ \
3---- 2
/
0---- 1
This repeats at 7-fold increasing scale, with the 1, 2 and 6 sub-sections reversed (mirror image). The next scale level can be seen at the multiple of 7 points 0,7,14,21,28,35,42,49.
42
----------- ---
35 ---
----------- ---
28 49 ---
---
---- 14
--- ----------- |
21 |
|
|
|
---- 7
-----
0 ---
Notice this is the same shape as the 0 to 6, but rotated 20.68 degrees counter-clockwise. Each level rotates further and for example after 18 levels it goes all the way around and back to the first quadrant.
The effect of the rotation is to fill the whole plane, eventually. For example at N=8592 it returns to the X axis at X=-82,Y=0 and starts to go into Y<0 shortly after. Getting all the way around to fill the fourth quadrant X>0,Y<0 takes a long time though, something on the order N=7^17 (which is close to rounding off in 53-bit floats).
Fractal
The flowsnake can also be thought of as successively subdividing the line segments with suitably scaled copies of the 0 to 7 figure (or its reversal).
The code here could be used for that by taking points N=0 to N=7^level. The Y coordinates should be multiplied by sqrt(3) to make proper equilateral triangles, then a rotation and scaling to make the endpoint come out at 1,0 or wherever desired. With this the path is confined to a finite fractal boundary.
FUNCTIONS
$path = Math::PlanePath::MathImageFlowsnake->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. Integer positions are always just 1 apart either horizontally or vertically, so the effect is that the fraction part appears either added to or subtracted from X or Y.
SEE ALSO
Math::PlanePath, Math::PlanePath::KochCurve, Math::PlanePath::HilbertCurve, Math::PlanePath::PeanoCurve, Math::PlanePath::ZOrderCurve
HOME PAGE
http://user42.tuxfamily.org/math-image/index.html
LICENSE
Copyright 2010, 2011 Kevin Ryde
Math-Image 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.
Math-Image 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 Math-Image. If not, see <http://www.gnu.org/licenses/>.