Last active
October 30, 2015 08:38
-
-
Save mdickinson/926736f7e072f098cfc0 to your computer and use it in GitHub Desktop.
Code to create the third-order approximation to a 3d space-filling Hilbert curve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
def hilbert(): | |
""" | |
Return NumPy array of shape (512, 3) containing successive coordinates | |
for a third-order three-dimensional Hilbert curve. | |
""" | |
a,b,c=numpy.indices((8,)*3).reshape(3,-1) | |
d=c[:8];r=abs(d-3>>1);g=(d^d>>1)*73;f=g[abs(d-1)&6] | |
x,y=[g[c]>>r[b]^f[b],g[b]]>>r[a]^f[a] | |
return(([[x],[y],[g[a]]]>>c[:3,None]&1).T<<c[:3]).sum(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment