定位元素不重叠

发布于 2024-09-06 02:02:35 字数 195 浏览 8 评论 0原文

我有许多矩形元素想要放置在二维空间中。我计算每个元素的理想位置。现在我的问题是许多元素重叠,因为理想位置通常集中在一个区域。我想尽可能避免重叠(但不一定是完美的)。我该怎么做?

我听说物理模拟适合于此 - 这是正确的吗?任何人都可以提供示例/教程吗?

顺便说一句:我正在使用 XNA,如果您知道任何 .NET 库可以完成这项工作 - 请告诉我!

I have a number of rectangular elements that I want to position in a 2D space. I calculate an ideal position for each element. Now my problem is that many elements overlap as very often the ideal positions are concentrated in one region. I want to avoid overlap as much as possible (doesn't have to be perfect, though). How can I do this?

I've heard physics simulations are suitable for this - is that correct? And can anyone provide an example/tutorial?

By the way: I'm using XNA, if you know any .NET library that does exactly this job - tell me!

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

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

发布评论

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

评论(3

十秒萌定你 2024-09-13 02:02:36

您正在寻找的算法是线性插值。 XNA 有自己的 lerp 函数。

The algorithm that you are looking for is linear interpolation. XNA has its own lerp function.

黑寡妇 2024-09-13 02:02:35

使用物理引擎的一种方式是:

在每个矩形上放置正电荷(或某种排斥力)并模拟力和运动。此外,正如 Eyal 善意指出的那样,你还需要一些吸引力来防止它们逐渐消失。这可以通过弹簧来建模(正如埃亚尔指出的那样)。它们希望最终达到某种平衡,其中可能涉及不重叠的矩形。

我相信类似的想法(基于力的启发式)可用于确定图形的美观布局(节点和边)。

免责声明:我自己没有使用过这个。

希望有帮助!

One way the physics engine can be used:

Put positive electric charges (or some kind of repulsive force) on each rectangles and simulate the forces and movements. Also, as Eyal was kind enough to point out, you also need some attractive forces to keep them from drifting away. This can be modelled by springs (again as Eyal points out). They will hopefully end up in some sort of equilibrium which might involve non-overlapping rectangles.

I believe similar ideas (force based heuristics) are used in determining nice looking layouts of graphs (the nodes and edges one).

Disclaimer: I haven't used this myself.

Hope that helps!

生寂 2024-09-13 02:02:35

Box2D 是一个广泛使用的(免费)物理库,可以实现所需的任务:链接

Box2D is a widly used (free) physics library that can achieve the needed task: Link

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