不规则形状的碰撞检测 [英] Collision detection of irregular shapes

查看:293
本文介绍了不规则形状的碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何检查圆圈是否即将与正方形碰撞,我知道如何检测正方形是否将与正方形碰撞,但我如何检测多边形是否要碰撞与正方形?



或更好的是,当多边形将要与多边形碰撞时。



更好的是,当由不直线的形状组成的形状与另一个相似的形状,多边形或圆形/矩形碰撞时



有什么办法得到像素一个形状会占用,像素另一个形状会占用,并检查它们是否有任何相同?



我希望有一些解决方案,



我使用javascript和html5 canvas来执行此操作。 >解决方案

这不是一个简单的东西。如果你满意一个函数可以判断两个多边形是否发生碰撞(你可以回滚它们),那么解决方案就不那么难了。你只需要检查是否任何两个多边形的边彼此交叉或不。这可以通过一些数学,并与大形状或很多多边形,它可以吃掉性能。要解决这个问题,您可以使用空间分区和边界卷。



UPDATE:
您可以基于。然后你需要检查这一点是否在两个段。为此,您可以使用段的端点,如果段实际包含该点,ua和ub变量将在0-1之间。


I know how to check if a circle is about to collide with a square, and I know how to detect if a square is about to collide with a square, but how would I go about detecting if a polygon is about to collide with a square?

Or better yet, when a polygon is about to collide with a polygon.

OR better yet, when a shape made up of lines that are not straight collides with another similar shape, a polygon, or a circle/rectangle

Is there any way to get the pixels a shape would take up maybe and the pixels another shape would take up and check if any of them are the same?

I am hoping there is some solution that doesn't require a ton of shape specific calculation.

I am using javascript and html5 canvas to do this.

解决方案

This is not a simple stuff. If you are satisfied that a function can tell if two polygons are colliding (and you can roll back them), then the solution is not so hard. You just need to check if any two of the polygon's sides are crossing each other or not. This can be done by some math, and with big shapes or lot polygons it can eat away the performance. To solve this, you may use space partitioning and bounding volumes.

UPDATE: You can calculate the intersection of lines based on this. Then you need to check if this point is in both segment or not. To do this, you can use the endpoints of the segments, and the ua and ub variables will be between 0-1 if the segment actually contains the point.

这篇关于不规则形状的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆