gpt4 book ai didi

objective-c - 如何缩放 mandelbrot 集

转载 作者:搜寻专家 更新时间:2023-10-30 20:07:32 24 4
gpt4 key购买 nike

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

最佳答案

假设中心是(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)。最后,将其移动到您指定的中心。

关于objective-c - 如何缩放 mandelbrot 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4405381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com