旋转矩形碰撞

发布于 2024-11-11 00:06:34 字数 70 浏览 0 评论 0原文

确定一个轴对齐的矩形是否与一个旋转的矩形碰撞的最有效方法是什么?每个类都有一个位置向量和一个大小向量,旋转后的类有一个角度值。

What is the most efficient way to find out if one axis aligned rectangle is colliding with one rotated rectangle? Each class has a position vector and a size vector and the rotated class has an angle value.

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

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

发布评论

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

评论(2

伪心 2024-11-18 00:06:34

您想要使用分离轴定理 (SAT)。通常它在 3d 中使用,但它可以很好地折叠到 2d。由于您遇到了特殊情况,因此您需要考虑的唯一轴是矩形的 4 个主轴:

[ 1,0 ]
[ 0,1 ]
[ sin(theta), cos(theta) ]
[ -cos(theta), sin(theta) ]

要检查轴,请计算每个顶点与该轴的点积。然后检查两组值的最小值和最大值,看看它们是否重叠。如果 4 个轴中的任何一个给出不重叠的范围,则矩形不会重叠(您已经找到了一个分离轴)。如果所有 4 个轴都显示重叠,则矩形相交。

这是最近关于同一问题的一个问题:
分离轴定理和Python

这是维基百科文章

http://en.wikipedia.org/wiki/Separating_axis_theorem

You want to use the Separating Axis Theorem (SAT). Normally it's used in 3d, but it collapses to 2d quite well. Since you've got a special case, the only axis you need to consider are 4 main axis of your rectangles:

[ 1,0 ]
[ 0,1 ]
[ sin(theta), cos(theta) ]
[ -cos(theta), sin(theta) ]

To check an axis, compute the dot product of every vertex with that axis. Then check the min and max of the 2 sets of values to see if they overlap. If any of the 4 axis gives ranges that don't overlap then the rectangles do not overlap (you've found a separating axis). If all 4 axis show overlap then the rectangles intersect.

Here is a recent SO question on the same problem:
Separating Axis Theorem and Python

And here is the wikipedia article

http://en.wikipedia.org/wiki/Separating_axis_theorem

最美的太阳 2024-11-18 00:06:34

最有效的方法是创建一个更大的矩形来包围旋转的矩形,并根据边界矩形进行碰撞检测。

这意味着边界矩形碰撞并不意味着“命中”,而是意味着值得进一步研究的条件。调查的方法根据您可以做出的假设而有所不同。在最简单的情况下,您可以通过 AND 像素检查真实输出。

然后,您可以使用这个“已确认”的命中来使用更复杂的模型进行分析;一种考虑碰撞的角度、速度、几何形状和弹性(或任何你感兴趣的东西)的模型。

存在更复杂的模型,但通常更复杂的模型需要更多的计算能力。通过设置一系列快速、快速的检查,可以更轻松地节省计算能力,并且只在能够获得回报的情况下才使用繁重的计算周期。

The most efficent way is to create a larger rectangle which bounds the rotated rectangle, and the do collision detection based on the bounding rectangles.

This means that bounding rectangle collisions don't signify "hits" but rather conditions which merit further investigation. Means of investigating differ depending on what assumptions you can make. In the simplest cases, you could AND pixels checking for a true output.

You could then use this "confirmed" hit to do an analysis with a more sophisticated model; one that takes into account the angles, velocities, geometry, and elasticity of the collision (or whatever you're interested in).

More sophisticated models exist, but generally the more sophisticated models require more computational power. It's easier to save your computational power by setting up a series of fast, quick checks and only bring out the heavy compute cycles for the cases where they are going to pay off.

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