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

发布于 2024-07-09 14:02:28 字数 365 浏览 10 评论 0原文

下面是我如何设置表示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半世蒼涼 2024-07-16 14:02:28

这是我如何设置表示 MandelBrot 集的数组的伪代码,但它
当纵横比为 1:1 时,会变得可怕地拉伸。

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

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

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

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

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;

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.

╭⌒浅淡时光〆 2024-07-16 14:02:28

确保你的演员阵容全部正确。 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).

拔了角的鹿 2024-07-16 14:02:28

它可能与您显示 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] = ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文