我正在尝试使用 OpenGL 来可视化 Mandelbrot 集,并且在平滑着色方面发现了非常奇怪的行为。
让我们假设,对于当前的复数值 C
, 算法在 n
后逃逸迭代时 Z
已被证明大于2。
我编写了这样的着色部分:
if(n==maxIterations){
color=0.0; //0.0 is black in OpenGL when put to each channel of RGB
//Points in M-brot set are colored black.
} else {
color = (n + 1 - log(log(abs(Z)))/log(2.0) )/maxIterations;
//continuous coloring algorithm, color is between 0.0 and 1.0
//Points outside M-brot set are colored depending of their absolute value,
//from brightest near the edge of set to darkest far away from set.
}
glColor3f(color ,color ,color );
//OpenGL-command for making RGB-color from three channel values.
问题是,这行不通。一些平滑是值得注意的,但并不完美。
但是当我添加两个额外的迭代时(只是在某处没有解释)
Z=Z*Z+C;
n++;
在计算颜色之前的“else”分支中,图像绝对流畅。
为什么会发生这种情况?为什么我们需要在检查要设置的点后在着色部分放置额外的迭代?
最佳答案
我实际上并不确定,但我猜这与一个数字( log(log(n))
)的对数的对数对于“小”数字 n
来说有点不稳定的事实有关。 ,在这种情况下,“小”意味着接近 2。如果您的 Z
刚刚逃脱,接近2。如果继续迭代,你(很快)离2越来越远,log(log(abs(Z)))
稳定,从而为您提供更可预测的值......然后,为您提供更平滑的值。
示例数据,任意选择:
n Z.real Z.imag |Z| status color
-- ----------------- ----------------- ----------- ------- -----
0 -0.74 -0.2 0.766551 bounded [nonsensical]
1 -0.2324 0.096 0.251447 bounded [nonsensical]
2 -0.69520624 -0.2446208 0.736988 bounded [nonsensical]
3 -0.31652761966 0.14012381319 0.346157 bounded [nonsensical]
4 -0.65944494902 -0.28870611409 0.719874 bounded [nonsensical]
5 -0.38848357953 0.18077157738 0.428483 bounded [nonsensical]
6 -0.62175887162 -0.34045357891 0.708867 bounded [nonsensical]
7 -0.46932454495 0.22336006613 0.519765 bounded [nonsensical]
8 -0.56962419064 -0.40965672279 0.701634 bounded [nonsensical]
9 -0.58334691196 0.26670075833 0.641423 bounded [nonsensical]
10 -0.4708356748 -0.51115812757 0.69496 bounded [nonsensical]
11 -0.77959639873 0.28134296385 0.828809 bounded [nonsensical]
12 -0.2113833184 -0.63866792284 0.67274 bounded [nonsensical]
13 -1.1032138084 0.070007489775 1.10543 bounded 0.173185134517425
14 0.47217965836 -0.35446645882 0.590424 bounded [nonsensical]
15 -0.64269284066 -0.53474370285 0.836065 bounded [nonsensical]
16 -0.6128967403 0.48735189882 0.783042 bounded [nonsensical]
17 -0.60186945901 -0.79739278033 0.999041 bounded [nonsensical]
18 -1.0135884004 0.75985272263 1.26678 bounded 0.210802091344997
19 -0.29001471459 -1.7403558114 1.76435 bounded 0.208165835763602
20 -3.6847298156 0.80945758785 3.77259 ESCAPED 0.205910029166315
21 12.182012228 -6.1652650168 13.6533 ESCAPED 0.206137522227716
22 109.65092918 -150.41066764 186.136 ESCAPED 0.20614160700086
23 -10600.782669 -32985.538932 34647.1 ESCAPED 0.20614159039676
24 -975669186.18 699345058.7 1.20042e+09 ESCAPED 0.206141590396481
25 4.6284684972e+17 -1.3646588486e+18 1.44101e+18 ESCAPED 0.206141590396481
26 -1.6480665667e+36 -1.263256098e+36 2.07652e+36 ESCAPED 0.206141590396481
注意颜色值在 [20,22] 中的 n 处仍然波动,在 n=23 时稳定,从 n=24 开始保持一致。并注意 Z 值在半径 2 的圆之外,该圆限定了 Mandelbrot 集。
我实际上还没有做足够的数学来确定这实际上是一个可靠的解释,但这将是我的猜测。
关于opengl - 分形的连续着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3768089/