Math::PlanePath::HilbertMidpoint -- Hilbert curve midpoints
use Math::PlanePath::HilbertMidpoint; my $path = Math::PlanePath::HilbertMidpoint->new; my ($x, $y) = $path->n_to_xy (123);
In progress ...
This is the midpoints of each segment of the HilbertCurve.
| \ 14 | 62 48----47 43----42 | \ / \ / \ 13 | 61 49 46 44 41 | / \ \ / / 12 | 60 50 45 40 | / \ / 11 | 59 51 39 | | | \ 10 | | 55 | 33 38 | | / \ | / \ \ 9 | 58 56 54 52 32 34 37 | \ / \ / | \ / 8 | 57 53 | 35----36 | | 7 | 31 | | 6 | 5 9 | 27----26 | / \ / \ | / \ 5 | 4 6 8 10 30 28 25 | | \ / | \ / / 4 | | 7 | 29 24 | | | / 3 | 3 11 23 | \ / \ 2 | 2 12 17 22 | \ / / \ \ 1 | 1 13 16 18 21 | / \ / \ / Y=0| 0 14----15 19----20 +---------------------------------------------- X=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
The X,Y coordinates are kept as integers by doubling the segment lengths,
*---5---* *---9---* | | | | 4 6 8 10 | | | | * *---7---* * | | 3 11 | | *---2---* *--12---* | | 1 13 | | *---0---* *--14---*--15--
The effect is to visit 1 of every 4 points in the first quadrant.
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::HilbertMidpoint->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.
$n
$n < 0
$n = $path->n_start()
Return 0, the first N in the path.
Math::PlanePath, Math::PlanePath::HilbertCurve, Math::PlanePath::DragonMidpoint
http://user42.tuxfamily.org/math-planepath/index.html
Copyright 2011, 2012 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath 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-PlanePath 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-PlanePath. If not, see <http://www.gnu.org/licenses/>.
To install Math::PlanePath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::PlanePath
CPAN shell
perl -MCPAN -e shell install Math::PlanePath
For more information on module installation, please visit the detailed CPAN module installation guide.