Re: need recursive function of the Peano curve



That looks a lot like a matrix self-similarity
of the Hadamard kind only the blocks are rotated.
If you look at it modulo 3 it appears to be blocks of:
{{0,1,2},
{2,1,0},
{0,1,2}}
I think.
paulgfx@xxxxxxxxx wrote:
Today I tried harder to do it myself and I had success.
Because I found a solution and I think that someone else perhaps
searching for it, I am posting the solution here. This solution was
tested, it works and it's very simple. It fills an array of NxN (where
N is a power of 3) with numbers arranged on the Peano curve (Hilbert
II).
Hope it helps anyone who want a recursive function of peano curve:

Example result:
N=3
[[0 1 2]
 [5 4 3]
 [6 7 8]]


N=9 [[ 0 1 2 15 16 17 18 19 20] [ 5 4 3 14 13 12 23 22 21] [ 6 7 8 9 10 11 24 25 26] [47 46 45 44 43 42 29 28 27] [48 49 50 39 40 41 30 31 32] [53 52 51 38 37 36 35 34 33] [54 55 56 69 70 71 72 73 74] [59 58 57 68 67 66 77 76 75] [60 61 62 63 64 65 78 79 80]]

Here is the python code (hope that tabs are preserved :)

#!/usr/bin/python
from Numeric import *

#Python implementation of the peano curve (hilbert type 2)
#by Nasca Octavian Paul, Tg. Mures, Romania
#released under Public Domain
#
#a is an array of size NxN
#x0,y0 are the points of the up-left corner
#xm,ym have value 0 for non-reversed and 1 for reversed
#     (xm for the x direction, and ym for y direction)
#N is the size of the array (it must be power of 3 like 3,9,27,81,729)
#K is a list of size 1 (it's used to pass it by refference); K must be
equal to [0]
#verical is True for vertical mode and False for horizontal mode of the
arrangement of the array
def peano(a,x0,y0,xm,ym,N,K,vertical):
    if N<=1:
        if vertical:
            a[x0,y0]=K[0];
        else:
            a[y0,x0]=K[0];
        K[0]+=1;
    else:
        N/=3;
        peano(a,x0+2*xm*N,y0+2*ym*N,xm,ym,N,K,vertical);
        peano(a,x0+2*xm*N,y0+1*N,1-xm,ym,N,K,vertical);
        peano(a,x0+2*xm*N,y0+2*(1-ym)*N,xm,ym,N,K,vertical);

        peano(a,x0+1*N,y0+2*(1-ym)*N,xm,1-ym,N,K,vertical);
        peano(a,x0+1*N,y0+1*N,1-xm,1-ym,N,K,vertical);
        peano(a,x0+1*N,y0+2*ym*N,xm,1-ym,N,K,vertical);

        peano(a,x0+2*(1-xm)*N,y0+2*ym*N,xm,ym,N,K,vertical);
        peano(a,x0+2*(1-xm)*N,y0+1*N,1-xm,ym,N,K,vertical);
        peano(a,x0+2*(1-xm)*N,y0+2*(1-ym)*N,xm,ym,N,K,vertical);



#example
N=9 #always must be power of 3, otherwise you'll get bad results
a=zeros((N,N));

peano(a,0,0,0,0,N,[0],False);

print (transpose(a));

.



Relevant Pages

  • Re: need recursive function of the Peano curve
    ... Your procedure is "more primitive" than a Hilbert and more like what is called a Gosper space fill. ... It fills an array of NxN with numbers arranged on the Peano curve. ...
    (sci.fractals)
  • Re: need recursive function of the Peano curve
    ... A square array is better. ... So that this spacefill goes up by powers of two instead of by powers of 3... ... #verical is True for vertical mode and False for horizontal mode of the ... arrangement of the array ...
    (sci.fractals)
  • Re: Find value in array
    ... Raising any number to the power of 0 results in a value of 1, ... also array entered ... MAX/ROW formula gives a blank whereas INDEX/MATCH ... I guess INDEX and header row issue ...
    (microsoft.public.excel.worksheet.functions)
  • Re: IOCTL_POWER_XXX method calls
    ... certainly declare them unsafe as a Char*, ... might even work, since they're just string pointers, not embedded strings ... has two power states, A/C power running at full speed, and off. ... // in the managed array of bytes. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Find value in array
    ... Raising any number to the power of 0 results in a value of 1, ... Entered as an array using the key combination of CTRL,SHIFT,ENTER: ... MAX/ROW formula gives a blank whereas INDEX/MATCH ... I guess INDEX and header row issue ...
    (microsoft.public.excel.worksheet.functions)