如何对Mandelbrot Set执行简单缩放

Leg*_*las 2 c++ mandelbrot

我对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();
Run Code Online (Sandbox Code Playgroud)

接下来,我选择一个正方形区域,这些是最左上角(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();

     }

 }
Run Code Online (Sandbox Code Playgroud)

我很难搞清楚数学,还有关于生成"缩放"视图的问题,我们非常感谢!

Mon*_*key 7

这是一个线性缩放.让我们在一维中完成它.您有屏幕空间(屏幕坐标)和图像空间(复杂平面,在您的情况下)

  • 屏幕空间=> [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);
Run Code Online (Sandbox Code Playgroud)

这相当于我展示的内容.但是你呢

double newMaxRe = MaxRe + (Re_factor* x2);
Run Code Online (Sandbox Code Playgroud)

这是不正确的,应该是

double newMaxRe = MinRe + (Re_factor* x2);
Run Code Online (Sandbox Code Playgroud)

你的循环中应该是同样的问题

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();
  }
}
Run Code Online (Sandbox Code Playgroud)

额外优点的其他细节:正确地对图像空间进行采样,我建议这样做

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

+0.5术语是在像素中间采样...