为什么会产生拉伸的分形?

时间:2023-01-14 08:58:23

Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1.

下面是我如何设置表示MandelBrot集合的数组的伪代码,但是当保留1:1的宽高比时,它会变得非常紧张。

xStep = (maxX - minX) / width;
yStep = (maxY - minY) / height;

for(i = 0; i < width; i++)
 for(j = 0; j < height; j++)
  {
   constantReal = minReal + xStep * i;
   constantImag = minImag + yStep * j;
   image[i][j] = inSet(constantReal, constantImag);
  }

Thanks!

3 个解决方案

#1


7  

Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1.

下面是我如何设置表示MandelBrot集合的数组的伪代码,但是当保留1:1的宽高比时,它会变得非常紧张。

xStep = (maxX - minX) / width;
yStep = (maxY - minY) / height;

Aha! It's because you must keep the same aspect ratio both for the image you will draw and for the region of the complex plane you want to draw. In other words, it must hold

啊哈!这是因为您必须为要绘制的图像和要绘制的复杂平面区域保持相同的宽高比。换句话说,它必须坚持

 width     maxX - minX
---------- = ---------------------
 height    maxY - minY

(It follows that xStep == yStep.) Your code probably does not enforce this requirement.

(它遵循xStep == yStep。)您的代码可能不会强制执行此要求。

#2


0  

Make sure your casts are all correct. xStep and yStep might be the products of integer division instead of the expected floating point division (if that's C# in your sample, it would require some explicit casts to work correctly).

确保你的演员都是正确的。 xStep和yStep可能是整数除法的乘积而不是预期的浮点除法(如果样本中的C#,则需要一些显式强制转换才能正常工作)。

#3


0  

It probably has to do with how you are displaying the image array. You use the width variable i as the first index, but usually the first index should be the slowest changing, that is, the height.

它可能与您如何显示图像阵列有关。您使用宽度变量i作为第一个索引,但通常第一个索引应该是最慢的变化,即高度。

Try changing the last line to image[j][i] = ...

尝试将最后一行更改为图像[j] [i] = ...

#1


7  

Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1.

下面是我如何设置表示MandelBrot集合的数组的伪代码,但是当保留1:1的宽高比时,它会变得非常紧张。

xStep = (maxX - minX) / width;
yStep = (maxY - minY) / height;

Aha! It's because you must keep the same aspect ratio both for the image you will draw and for the region of the complex plane you want to draw. In other words, it must hold

啊哈!这是因为您必须为要绘制的图像和要绘制的复杂平面区域保持相同的宽高比。换句话说,它必须坚持

 width     maxX - minX
---------- = ---------------------
 height    maxY - minY

(It follows that xStep == yStep.) Your code probably does not enforce this requirement.

(它遵循xStep == yStep。)您的代码可能不会强制执行此要求。

#2


0  

Make sure your casts are all correct. xStep and yStep might be the products of integer division instead of the expected floating point division (if that's C# in your sample, it would require some explicit casts to work correctly).

确保你的演员都是正确的。 xStep和yStep可能是整数除法的乘积而不是预期的浮点除法(如果样本中的C#,则需要一些显式强制转换才能正常工作)。

#3


0  

It probably has to do with how you are displaying the image array. You use the width variable i as the first index, but usually the first index should be the slowest changing, that is, the height.

它可能与您如何显示图像阵列有关。您使用宽度变量i作为第一个索引,但通常第一个索引应该是最慢的变化,即高度。

Try changing the last line to image[j][i] = ...

尝试将最后一行更改为图像[j] [i] = ...