Mandelbrot设置不显示在中心

时间:2017-06-11 01:41:14

标签: c++ fractals

我认为问题是我如何将笛卡尔坐标转换为复数,但我现在已经知道如何。你能解释一下我该如何转换?这是我尝试过的:

double c_Im = (y + (maxIm - minIm)) / height;
double c_Re = (x + (maxRe - minRe)) / width;

代码:

float minRe = -2.0;
float maxRe = 2.0;
double minIm = -2.0;
double maxIm = 2.0;

for (size_t y = 0; y < height; y++)
    {
        double c_Im = (y + (maxIm - minIm)) / height;

        for (size_t x = 0; x < width; x++)
        {
            double c_Re = (x + (maxRe - minRe)) / width;
            float dx = 0, dy = 0;
            int z = 0;
            while (dx * dx + dy * dy < 4 && z < maxIterator)
            {
                float temp = (dx * dx - dy * dy) + c_Re;
                dy = 2 * dx * dy + c_Im;
                dx = temp;
                z++;
            }
            image.setPixel(x, y, Color(z % 255, z % 255, z % 255));

        }
    }

not_expected_output.jpg not expected output

1 个答案:

答案 0 :(得分:1)

我认为您正在寻找的公式是:

double c_Im = y * (maxIm - minIm) / height + minIm;

double c_Re = x * (maxRe - minRe) / width + minRe;

这是从地图公式得出的:Y =(X-A)*(D-C)/(B-A)+ C