Re: [math-fun] Hilbert curves
Found this page: http://people.csail.mit.edu/jaffer/Geometry/HSFC Pretty much searching for "Butz Hilbert". Jaffer complains that the existing implementations of Butz's multi-dimensional Hilbert curve algorithm 1) are hard to read, 2) take the number of bits of precision as an argument (instead of letting it be whatever the arguments require), and 3) are limited by the precision of the representations they use for distance-along-curve, for instance to 32 bits, for the product (number of dimensions x bits of resolution in each). So, he develops a Scheme algorithm that uses bignums and works "in terms of higher level constructs: Gray-code, lamination, rotation and reflection." This sounds like the right approach to me (although it might need optimizing/obfuscating again in the end), but I'm still having problem 1) at the moment. Here's the main routine (mainly to show its length): (define (integer->hilbert-coordinates scalar rank . nbits) (define igry (integer->gray-code scalar)) (define rnkmsk (lognot (ash -1 rank))) (define rnkhib (ash 1 (+ -1 rank))) (define rank*nbits (if (null? nbits) (let ((rank^2 (* rank rank))) (* (quotient (+ -1 rank^2 (integer-length scalar)) rank^2) rank^2)) (* rank (car nbits)))) (do ((bdxn (- rank rank*nbits) (+ rank bdxn)) (chnk (ash igry (- rank rank*nbits)) (logxor rnkhib (logand (ash igry (+ rank bdxn)) rnkmsk))) (rotation 0 (modulo (+ (log2-binary-factors chnk) 2 rotation) rank)) (flipbit 0 (ash 1 rotation)) (lst '() (cons (logxor flipbit (rotate-bit-field chnk rotation 0 rank)) lst))) ((positive? bdxn) (map gray-code->integer (delaminate-list rank (reverse lst)))))) Further rationale: http://people.csail.mit.edu/jaffer/Geometry/RFMDSFF Also, He develops a Peano-curve-based method that fills all space instead of just a >=0 corner. He measures distance on the curve vs. Euclidean distance for various curves. --Steve
participants (1)
-
Steve Witham