2013-04-04 94 views
0

我對Java還比較陌生。我一直在製作一個程序來顯示mandelbrot集。我目前的代碼生成的圖像很接近,但不是mandelbrot集。這是我這一代的代碼:java中的mandelbrot設置不正確

private void generateMap() { 
    // scale, ITERATIONS, map, and SIZE are class variables 
    // cR and cI are the actual coordinates in the set being used 
    double cR = -2*scale; 
    double cI = -2*scale; 
    // a and b step through the array used to store the drawing 
    // and control when the loop exits 
    for (int a = 0; a < SIZE.width; a++) 
    { 
     for (int b = 0; b < SIZE.height; b++) 
     { 
      double xR = 0; 
      double xI = 0; 
      int iter = 0; 
      while (iter < ITERATIONS) 
      { 
       xR = (xR*xR-xI*xI) + cR; 
       xI = (2*xR*xI) + cI; 
       if (xR*xR+xI*xI > 4) { 
        map[a][b] = iter; 
        iter = ITERATIONS; 
       } 
       iter++; 
      } 
      cI += INCREMENT*scale; 
     } 
     cI = -2*scale; 
     cR += INCREMENT*scale; 
    } 
} 

我的NetBeans項目是從here下載。

這裏的電流輸出的屏幕截圖: screenshot

+0

不是您的問題,但你的while循環可以被重寫:'用於(INT ITER = 0; ITER 4){map [a] [b] = iter;打破; }}' – assylias 2013-04-04 23:50:12

+1

爲了更快得到更好的幫助,請發佈[SSCCE](http://sscce.org/)並鏈接到當前和預期輸出的圖像。 – 2013-04-05 00:18:12

回答

0

xR的和十一的新值沒有被一致計算。 xR基於其先前的值計算,而xI基於xR的新值計算。嘗試類似下面的內容或者使用複數類。

double r = xR; 
double i = xI; 
xR = (r*r-i*i) + cR; 
xI = (2*r*i) + cI;