# 希尔伯特曲线及性质的形式化理解

n阶的希尔伯特曲线是从$$[0, 1]$$区间到$$[0, 1]\times[0, 1]$$平面区域的映射$$f_n$$, 把0和1映射到区域左下角和右下角:

$f_n(0)=(0, 0), \quad f_n(0)=(1, 0)$

$f(x) := \lim_{n\to \infty} f_n(x)$

## 3. 附录

from matplotlib import pyplot as plt
import numpy as np
import math

# generate psedo Hilbert curve - the function from 1d to 2d
order = 11
phc = [
[[0,0]]  # order 0
]
for o in range(order):
new_phc = []
new_phc += [[y, x] for x, y in phc[o]]  # left bottom
new_phc += [[x, y + 2**o] for x, y in phc[o]]  # left top
new_phc += [[x + 2**o, y + 2**o] for x, y in phc[o]]  # right top
new_phc += [[2**o - 1 - y + 2**o, 2**o - 1 - x] for x, y in phc[o]]  # right bottom
phc.append(new_phc)

# plot these curves
for o in range(order):
fig = plt.figure(o, figsize=(6,6))
plt.axis('off')
plt.plot(
list(map(lambda p:p[0], phc[o+1])),
list(map(lambda p:p[1], phc[o+1]))
)
fig.savefig('order_{}.png'.format(o+1))
if o+1 != order:
plt.close(fig)
plt.show()

# colorize the pixels in order, for visualization
size = 2**order
imax = size*size
image = [[0]*size for i in range(size)]
i = 0
for x,y in phc[order]:
image[size-1-y][x] = i
i += 1

plt.imshow(image)
plt.show()
plt.imsave('hilbert.png', image)


posted @ 2017-10-08 04:35  zzdyyy  阅读(6485)  评论(0编辑  收藏  举报