Gab*_*iel 4 c math fractals mandelbrot
我正在编写一个用 C 语言绘制 Mandelbrot 集的程序。我已经能够显示它并且看起来不错,但是当我减少迭代次数时,我得到了这种效果,生成了我只能描述为“云”的效果:

它应该是这样的(我从网站上得到的):
我怎样才能让我的看起来像上面的那样?这是绘制单个点的代码:
double getFracPoint(double x,double y){
//scale x and y
x = x * ((plotEnd.x-plotStart.x) / SCREENWIDTH) + plotStart.x;
y = y * ((plotEnd.y-plotStart.y) / SCREENHEIGHT) + plotStart.y;
x/=zoom;
y/=zoom;
//instead of using the complex number library of the C standard
//I decided to use regular numbers as it turns out to be faster.
//The first number is the real part the second number is the imaginary
//part.
double z[2];
z[0] = z[1] = 0;
double c[2];
c[0] = x;
c[1] = y;
int n = 0;
for(int i = 0; i < ITERS; i++,n++){
//if it's out of boundaries we are sure it does not belong to the set.
if(z[0] > 4 || -4 > z[0] || -4 > z[1] || 4 < z[1])
break;
double t = z[1]; //store z[1]
//multiply z to itself
z[1] = (z[0] * z[1]) + (z[0] * z[1]);
z[0] = z[0] * z[0] + -(t*t);
//add C to Z
z[0] += c[0];
z[1] += c[1];
}
return (double)n/(double)ITERS;
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
您的“出界”测试检查是否z落在半径为 4 的正方形内:
if(z[0] > 4 || -4 > z[0] || -4 > z[1] || 4 < z[1])
Run Code Online (Sandbox Code Playgroud)
然而,典型的测试是检查距原点的欧几里得距离(即复数范数,即检查它是否落在半径为 4 的圆内):
if(z[0]*z[0] + z[1]*z[1] > 4*4)
Run Code Online (Sandbox Code Playgroud)