- UID
- 352
- 帖子
- 1321
- 精华
- 14
- 积分
- 2599
- 来自
- 河南永城
|
这个封闭希尔伯特曲线如何迭代完成
http://www.inrm3d.cn/viewthread.php?tid=4412&extra=page%3D5
HilbertCurve(BOTH) {
; By Samuel Monnier, 2.9.00 简化
init:
z = 0
int i = 0
int ttype = 0
float d = -1
loop:
final:
z = #z/2
z = abs(z) - (.5,.5)
while i < @niter
i = i + 1
if ttype == 0
if real(z) < 0 && imag(z) < 0
z = 2*z + (.5,.5)
z = -conj(z)
elseif real(z) > 0 && imag(z) < 0
z = 2*z + (-.5,.5)
z = 1i*z
elseif real(z) > 0 && imag(z) > 0
z = 2*z + (-.5,-.5)
z = 1i*conj(z)
elseif real(z) < 0 && imag(z) > 0
z = 2*z + (.5,-.5)
ttype = 1
endif
else
if real(z) < 0 && imag(z) < 0
z = 2*z + (.5,.5)
z = 1i*z
ttype = 0
elseif real(z) > 0 && imag(z) < 0
z = 2*z + (-.5,.5)
z = -1i*conj(z)
ttype = 0
elseif real(z) > 0 && imag(z) > 0
z = 2*z + (-.5,-.5)
ttype = 0
elseif real(z) < 0 && imag(z) > 0
z = 2*z + (.5,-.5)
z = -conj(z)
ttype = 0
endif
endif
endwhile
z = z + (1,1)
if ttype == 0
if abs(real(z))-1 > d
d = abs(real(z))-1
endif
if abs(imag(z))-1 > d
d = abs(imag(z))-1
endif
else
d = imag(z)-1
endif
#index = abs(d)^@power
default:
title = "Hilbert Curve"
param power
caption = "Thickness"
default = .1
endparam
param niter
caption = "Number of Iterations"
default = 3
endparam
} |
|