Created
January 29, 2021 01:08
-
-
Save astoeckel/bfeb0e3486cecbbf72e2ee273075f9b0 to your computer and use it in GitHub Desktop.
Python 2D z-order curve
This file contains 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
def zorder(N): | |
if N == 0: | |
return np.zeros((0, 0), dtype=np.int) | |
elif N == 1: | |
return np.zeros((1, 2), dtype=np.int) | |
else: | |
pnts = zorder(N - 1) | |
l = pnts.shape[0] | |
offs = 2 ** (N - 2) | |
res = np.zeros((4 * l, 2), dtype=np.int) | |
for i in range(2): | |
for j in range(2): | |
i0, i1 = (2 * i + j) * l, (2 * i + j + 1) * l | |
res[i0:i1, 0] = pnts[:, 0] + j * offs | |
res[i0:i1, 1] = pnts[:, 1] + i * offs | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment