2010-12-10 36 views
1

我已經成功實現了mandelbrot集,如維基百科文章中所述,但我不知道如何放大特定部分。這是我使用的代碼:如何縮放mandelbrot集

+(void)createSetWithWidth:(int)width Height:(int)height Thing:(void(^)(int, int, int, int))thing 
{ 
    for (int i = 0; i < height; ++i) 
    for (int j = 0; j < width; ++j) 
    { 
     double x0 = ((4.0f * (i - (height/2)))/(height)) - 0.0f; 
     double y0 = ((4.0f * (j - (width/2)))/(width)) + 0.0f; 
     double x = 0.0f; 
     double y = 0.0f; 

     int iteration = 0; 
     int max_iteration = 15; 

     while ((((x * x) + (y * y)) <= 4.0f) && (iteration < max_iteration)) 
     { 
      double xtemp = ((x * x) - (y * y)) + x0; 
      y = ((2.0f * x) * y) + y0; 
      x = xtemp; 
      iteration += 1; 
     } 

     thing(j, i, iteration, max_iteration); 
    } 
} 

這是我的理解是X0應該在-2.5範圍 - 1,Y0應在-1範圍 - 1,和減少數量將會放大,但那根本沒有用。我如何縮放?

+0

此外,整個集合包含在-2 2010-12-10 04:06:39

+0

對於「永無止境的縮放」,我相信分形算法本身的一些特性被使用。 – 2010-12-10 04:21:02

回答

2

假設的核心是(CX,CY)和長度要顯示爲(LX,LY),你可以使用下面的縮放公式:

x0 = cx +(i/width-0.5)* lx;

y0 = cy +(j/width-0.5)* ly;

它能做什麼是對像素的第一比例縮小到單位間隔(0 = < I /寬度< 1),則偏移的中心(-0.5 < = I /寬度0.5 < 0.5),擴展到您希望的尺寸(-0.5 * lx < =(i/width-0.5)* lx < 0.5 * lx)。最後,把它移到你給的中心。