本文介绍了如何确定两个凸多边形是否相交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时删除!!
假设在一个平面上有许多凸多边形,也许是一张地图。这些多边形可以相互碰撞并分享边缘,但不能重叠。
P 和 Q 是否重叠,首先我可以在 P 中测试每条边,看它是否与 Q 中的任何边相交。如果找到交点,我声明 P 和 Q 相交。如果没有相交,那么我必须测试 P 完全被 Q 包含的情况,反之亦然。接下来,就是 P == Q 的情况。最后,有这样的情况,分享一些优势,但不是全部。 (后两种情况可能被认为是相同的一般情况,但这可能并不重要。)
我有一种算法可以检测两条线段相交的位置。如果这两个部分是共线的,他们不会被认为是相交的。
我是否正确列举了这些情况?任何建议测试这些案件?
请注意,我不想找到新的凸多边形是交集,我只想知道是否存在交集。有很多有据可查的算法可以找到相交点,但我不需要花费所有的努力。
可以使用 :
Suppose there are a number of convex polygons on a plane, perhaps a map. These polygons can bump up against each other and share an edge, but cannot overlap.
To test if two polygons P and Q overlap, first I can test each edge in P to see if it intersects with any of the edges in Q. If an intersection is found, I declare that P and Q intersect. If none intersect, I then have to test for the case that P is completely contained by Q, and vice versa. Next, there's the case that P==Q. Finally, there's the case that share a few edges, but not all of them. (These last two cases can probably be thought of as the same general case, but that might not be important.)
I have an algorithm that detects where two line segments intersect. If the two segments are co-linear, they are not considered to intersect for my purposes.
Have I properly enumerated the cases? Any suggestions for testing for these cases?
Note that I'm not looking to find the new convex polygon that is the intersection, I just want to know if an intersection exists. There are many well documented algorithms for finding the intersection, but I don't need to go through all the effort.
解决方案
You could use this collision algorithm:
这篇关于如何确定两个凸多边形是否相交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
1403页,肝出来的..