2

我对 Mandelbrot 设置“缩放”视图和与之相关的数学有一个一般性的问题。我已经用值实现了 256 X 256 窗口大小的 mandelbrot 集

  // ImageWidth = ImageHeight = 256;

  double MinRe = -2.0;
  double MaxRe = 1.0;
  double MinIm = -1.2;
  double MaxIm = 1.8;

  ComputeMandelbrot();

接下来,我选择一个正方形区域,这些是最左上角 (76,55) 和最右下角 (116, 99) 的坐标(选择 44 边的正方形)

所以,我选择x2 = x1 + 44 ; y2 = y1 + 44;

如何将这些新坐标转换为复平面?以及新的实值和虚值将如何变化以便为新值集计算它?

这是我到目前为止所尝试的..

double Re_factor = (MaxRe-MinRe)/(ImageWidth-1);
double Im_factor = (MaxIm-MinIm)/(ImageHeight-1);

double newMinRe = MinRe + (Re_factor* x1);
double newMaxRe = MaxRe + (Re_factor* x2);
double newMinIm = MinIm + (Im_factor* y1);
double newMaxIm = MaxIm + (Im_factor* y2);

// and then I compute c - real and c- imag values

  for(unsigned y=0; y<ImageHeight; ++y) 
{ 
  double c_im = newMaxIm - y*Im_factor;
  for(unsigned x=0; x<ImageWidth; ++x)
    {
      double c_re = newMinRe + x*Re_factor;

      // ComputeMandelbrot();

     }

 }

我很难弄清楚数学,还有关于生成“缩放”视图,感谢任何帮助!

4

1 回答 1

7

这是一个线性缩放。让我们在 1D 中进行。您有屏幕空间(屏幕坐标)和图像空间(复平面,在您的情况下)

  • 屏幕空间 => [0, 255]
  • 图像空间 => [-2, 1]

所以要将坐标 X 从屏幕空间转换为图像空间 X'

X' =​​ (X / 255) * (1 - (-2)) + (-2)

为了使其更通用

  • 屏幕空间 => [SMin, SMax]
  • 图像空间 => [IMin, IMax]

X' =​​ ((X - SMin) / (SMax - SMin)) * (IMax - IMin) + IMin


在您的代码中,您可以

double newMinRe = MinRe + (Re_factor* x1);

这相当于我展示的内容。但是你这样做了

double newMaxRe = MaxRe + (Re_factor* x2);

这是不正确的,应该是

double newMaxRe = MinRe + (Re_factor* x2);

您的循环中存在同样的问题,应该是

for(unsigned y=0; y<ImageHeight; ++y)  { 
  double c_im = MinIm + y*Im_factor;
  for(unsigned x=0; x<ImageWidth; ++x) {
    double c_re = MinRe + x*Re_factor;
    // ComputeMandelbrot();
  }
}

额外细节的额外细节:为了正确采样图像空间,我建议这样做

for(unsigned SX = SMin; x < SMax; ++x) {
  double k = (double(SX + 0.5) - SMin) / (SMax - SMin);
  double IX = (k * (IMax - IMin)) + IMin;
}

+0.5 项是在像素的中间进行采样...

于 2011-12-05T06:38:55.470 回答