4

我已经成功实现了维基百科文章中描述的 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 范围内,并且减少该数字会放大,但这根本不起作用。如何缩放?

4

2 回答 2

5

假设中心是(cx, cy),要显示的长度是(lx, ly),可以使用如下缩放公式:

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

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

它的作用是首先将像素缩小到单位间隔(0 <= i/width < 1),然后移动中心(-0.5 <= i/width-0.5 < 0.5),放大到您想要的尺寸( -0.5*lx <= (i/width-0.5)*lx < 0.5*lx)。最后,把它移到你给定的中心。

于 2010-12-10T04:14:55.377 回答
2

首先,max_iteration 为 15,您不会看到太多细节。我的每个点有 1000 次迭代作为基线,并且在它真的变得太慢而无法等待之前可以进行大约 8000 次迭代。

这可能会有所帮助:http: //jc.unternet.net/src/java/com/jcomeau/Mandelbrot.java

这也是: http: //www.wikihow.com/Plot-the-Mandelbrot-Set-By-Hand

于 2010-12-10T03:47:30.893 回答