我有一个关于 Mandelbrot 集“缩放” View 及其相关数学的一般性问题。我已经为 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();
}
}
我很难弄清楚数学,以及关于生成“缩放” View 的问题,感谢任何帮助!!
最佳答案
这是线性缩放。让我们在 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 项是在像素的中间采样...
关于c++ - 如何对 Mandelbrot 集执行简单缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8381675/