如何实现菱形平方算法?

发布于 2024-12-18 10:19:15 字数 808 浏览 2 评论 0原文

我正在读这个:http://www.gameprogrammer.com/fractal.html#diamond

它说:

这是迭代细分例程的起点, 分两步:

菱形步骤:取一个由四个点组成的正方形,在正方形中点(两条对角线相交的地方)生成一个随机值。这 中点值是通过平均四个角值加上 随机数量。当你有多个时,这会给你钻石 排列成网格的正方形。

方形步骤:取每个菱形的四个点,在菱形的中心生成一个随机值。计算中点 通过平均角值加上生成的随机量来获得值 与金刚石台阶所用的范围相同。这给你正方形 再次。

我不明白这一点。取每个正方形的中点如何形成菱形?取每颗菱形的中点如何形成一个正方形?

有人可以提供与语言无关的代码来说明如何执行此操作吗?

编辑:

第 1 步:你有一个网格并使四个角统一高度:

* ┬ ┬ ┬ *
├ ┼ ┼ ┼ ┤
├ ┼ ┼ ┼ ┤
├ ┼ ┼ ┼ ┤
* ┴ ┴ ┴ *

第 2 步:你取正方形的中点并将其设置为所有 4 个角的平均值加上随机值:

* ┬ ┬ ┬ *
├ ┼ ┼ ┼ ┤
├ ┼ * ┼ ┤
├ ┼ ┼ ┼ ┤
* ┴ ┴ ┴ *

现在怎么办?我在任何地方都没有看到钻石

I was reading this: http://www.gameprogrammer.com/fractal.html#diamond

And it says:

This is the starting-point for the iterative subdivision routine,
which is in two steps:

The diamond step: Taking a square of four points, generate a random value at the square midpoint, where the two diagonals meet. The
midpoint value is calculated by averaging the four corner values, plus
a random amount. This gives you diamonds when you have multiple
squares arranged in a grid.

The square step: Taking each diamond of four points, generate a random value at the center of the diamond. Calculate the midpoint
value by averaging the corner values, plus a random amount generated
in the same range as used for the diamond step. This gives you squares
again.

I don't understand this. How does taking the midpoint of every square make a diamond? How does taking the midpoint of every diamond make a square?

Can someone provide language-agnostic code for how to do this?

Edit:

Step 1: you have a grid and make the four corners uniform height:

* ┬ ┬ ┬ *
├ ┼ ┼ ┼ ┤
├ ┼ ┼ ┼ ┤
├ ┼ ┼ ┼ ┤
* ┴ ┴ ┴ *

Step 2: you take the midpoint of the square and set it to the average of all 4 corners plus a random value:

* ┬ ┬ ┬ *
├ ┼ ┼ ┼ ┤
├ ┼ * ┼ ┤
├ ┼ ┼ ┼ ┤
* ┴ ┴ ┴ *

Now what? I don't see a diamond anywhere

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

泪意 2024-12-25 10:19:15

将两个方块放在一起:“当网格中有多个方块时,这会给你钻石。”正方形上方/下方相同。

平方步骤会生成一组新的正方形,与第一个正方形偏移,其顶点由菱形的中点定义。

Put two of the squares together: "this gives you diamonds when you have multiple squares in a grid." Same for above/below the square.

The squaring step makes a new set of squares, offset from the first, with the vertices defined by the diamond's midpoints.

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