开发者

a function which determines if a given point(x, y) is in the mandelbrot set or not

So given any point (a + ib), the function will return 1 if it is in the mandelbrot set or 0 if not for n amount of iterations.

I'm having difficulties trying to code this function, especially with the complex num开发者_如何转开发bers. Can anyone help me or give some advice for me to start?

So far I can only think of a way to determine if a real number (any x, y = 0) is in the mandelbrot set.

EDIT: Sorry forgot to say that I'm coding in C, I'm looking for some psuedocode ideas mostly though.


The Wikipedia page on the set has some pseudocode that does the basic job, and hints at some of the many directions in which you can take such a project. Understanding complex math is the key; it is traditional to keep the real and imaginary components of a complex as a pair of doubles and implement whatever operations you need on them by hand or as macros. (These days you can use the complex type if your compiler speaks C99, but where's the fun in that...? :-) )


You need to repeatedly square and add a complex number:

double a = real input component;
double b = imag input component;

double zReal = a;
double zImag = b;
for(int i = 0; i< LIMIT; i++){
   double temp = zReal;
   zReal = zReal * zReal - zImag * zImag;
   zImag = 2 * temp * zImag;
   if(zReal * zReal + zImag * zImag > 4){
      return 0;
   }
}
return 1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜