为什么这会产生拉伸的分形?
下面是我如何设置表示 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);
}
谢谢!
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.
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊哈! 这是因为您必须为要绘制的图像和要绘制的复杂平面区域保持相同的纵横比。 换句话说,它必须成立
(因此 xStep == yStep。)您的代码可能不强制执行此要求。
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
(It follows that xStep == yStep.) Your code probably does not enforce this requirement.
确保你的演员阵容全部正确。 xStep 和 yStep 可能是整数除法的乘积,而不是预期的浮点除法(如果您的示例中是 C#,则需要一些显式转换才能正常工作)。
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).
它可能与您显示
image
数组的方式有关。 您使用宽度变量 i 作为第一个索引,但通常第一个索引应该是变化最慢的,即高度。尝试将最后一行更改为
image[j][i] =
...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.Try changing the last line to
image[j][i] =
...