1 ## Copyright (C) 2009 Javier Enciso <j4r.e4o@gmail.com>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function file} {@var{x}, @var{y}} z_curve (@var{n})
18 ## Creates an iteration of the Z-order space-filling curve with @var{n} points.
19 ## The argument @var{n} must be of the form @code{2^M}, where @var{m} is an
20 ## integer greater than 0.
24 ## [x ,y] = z_curve (n);
25 ## line (x, y, "linewidth", 4, "color", "blue");
30 function [x, y] = z_curve (n)
36 check_power_of_two (n);
41 [x1, y1] = z_curve (n/2);
50 function check_power_of_two (n)
51 if (frac_part (log (n) / log (2)) != 0)
52 error ("z_curve: input argument must be a power of 2.")
56 function d = frac_part (f)
62 %! expect = [0, 1, 0, 1; 0, 0, -1, -1];
63 %! [get(1,:), get(2,:)] = z_curve (n);
64 %! if (any(size (expect) != size (get)))
65 %! error ("wrong size: expected %d,%d but got %d,%d", size (expect), size (get));
66 %! elseif (any (any (expect!=get)))
67 %! error ("didn't get what was expected.");
77 %! [x, y] = z_curve (n);
78 %! line (x, y, "linewidth", 4, "color", "blue");
79 %! % -----------------------------------------------------------------------
80 %! % the figure window shows an iteration of the Z-order space-fillig curve
81 %! % with 4 points on each axis.
86 %! [x, y] = z_curve (n);
87 %! line (x, y, "linewidth", 2, "color", "blue");
88 %! % ----------------------------------------------------------------------
89 %! % the figure window shows an iteration of the Z-order space-fillig curve
90 %! % with 32 points on each axis.