NAME
App::MathImage::PlanePath::Flowsnake -- self-similar path traversal
SYNOPSIS
use App::MathImage::PlanePath::Flowsnake;
my $path = App::MathImage::PlanePath::Flowsnake->new;
my ($x, $y) = $path->n_to_xy (123);
DESCRIPTION
This path is the flowsnake curve by William Gosper, done as 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 spaced out on every second X coordinate to make little triangles while 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 7 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 in 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 this is to fill the whole plane, eventually.
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 can 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 = App::MathImage::PlanePath::Flowsnake->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.
$n = $path->xy_to_n ($x,$y)
-
Return an integer point number for coordinates
$x,$y
. Each integer N is considered the centre of a unit square an$x,$y
within that square returns N.
SEE ALSO
Math::PlanePath, Math::PlanePath::HilbertCurve Math::PlanePath::PeanoCurve Math::PlanePath::ZOrderCurve
HOME PAGE
http://user42.tuxfamily.org/math-image/index.html
LICENSE
Math-Image is 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/>.