Opengl 分形的连续着色
我试图用OpenGL可视化Mandelbrot集,但在平滑着色方面发现了非常奇怪的行为 让我们假设,对于当前的复数值Opengl 分形的连续着色,opengl,fractals,Opengl,Fractals,我试图用OpenGL可视化Mandelbrot集,但在平滑着色方面发现了非常奇怪的行为 让我们假设,对于当前的复数值C,当Z被证明大于2时,n迭代后,算法已转义 我将着色部分编程如下: 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
C
,当Z
被证明大于2时,n
迭代后,算法已转义
我将着色部分编程如下:
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.
问题是,这根本不管用。一些平滑是可以注意到的,但并不完美
但是当我添加两个额外的迭代时(只是在某个地方发现了这个,没有解释)
在“else”分支中,在计算颜色之前,图片显示为绝对、优雅的平滑
为什么会发生这种情况?为什么在检查了要设置的点之后,我们需要在着色部分中放置额外的迭代?目前看来,“额外迭代”的想法没有令人信服的公式,如果不考虑它只是工作的事实的话
在Wikipedia的Mandelbrot文章的一个旧版本中,有几行关于连续着色的内容:
第二,建议几个
进行额外的迭代以使z
可以成长。如果您停止迭代为
z一逃走,就有了
平滑的可能性
算法不起作用
总比什么都没有好。我不太确定,但我猜这与一个数字的日志(
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值远远超出了限定Mandelbrot集的半径为2的圆
实际上,我还没有做足够的数学来确定这是一个可靠的解释,但这将是我的猜测。因为我刚刚做了相同的程序,作为一名优秀的数学家,我会解释为什么,希望它能清楚 假设在k次迭代后,带有种子C的序列已转义 由于函数本身被定义为极限,随着迭代次数趋于无穷大,得到接近k的值就不太好了。这就是原因 正如我们知道的,在2之后,序列变为无穷大,让我们考虑Z足够大的一些迭代T。考虑到这一点,C将是非常小的,因为通常情况下,您在[-2,2]和[-1.5,1.5]中查看2轴的集合。因此,在T+1迭代中,z将是上一次迭代的~~z^2,很容易检查,在这种情况下,T+1的| z |将是上一次迭代的~~~z | ^2 对于第k次迭代,我们的函数是log(| z |)/2^k。在我们正在研究的案例中 很容易看出,在T+1迭代中,它将是~~
(来源:) 这是T迭代时的函数 换句话说,随着| z |变得比种子C“显著”大,函数变得越来越稳定。您不希望使用接近转义迭代k的迭代,因为实际上Z将接近2,并且取决于C,与它相比,它可能不会太小,因此您不会接近极限 由于| C |接近2,实际上在第一次转义迭代中,您将远离极限。另一方面,如果您选择在| Z |>100之后进行转义,例如,或者只需再进行几次迭代,您将变得更加稳定
希望对这个问题感兴趣的人都能给他一个好的回答。只是出于好奇。那是什么语言?我想知道,因为它似乎有一个处理复杂数的ABS-()函数,这是VisualC++。代码是使用Visual C++的类编写的。在这里检查一下:我应该指出,我实际上并不确定这就是它的作用。在检查了其他一些数字之后,我所说的关于持续迭代稳定性的部分是准确的,但是一个点的第一次逃逸值和附近另一个点的第一次逃逸值之间的差异似乎并不大于5次迭代-过去逃逸值之间的差异。但也许我只是使用了碰巧评估结果非常相似的点?我必须更深入地探索它才能确定。
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