旋转的2d矩形交叉点检测 [英] Rotated 2d rectangle intersection detection
问题描述
我有2个矩形,它们被任意放置,我对所有四个角点进行矩形扩展,像
I have 2 rectangles they are placed arbitrarily and I have rects all four corner point like
struct Rect
{
NSPoint topLeft;
NSPoint topRight;
NSPoint bottomLeft;
NSPoint bottomRight;
}
我想检查两个矩形是否相交。我正在寻找一个类似于 NSIntersectsRect
的方法。但是 NSIntersectsRect
将不会遵守矩形的旋转。结构中的点是旋转后获得的点。
I want to check whether 2 rectangles intersects. I am looking a method similar to NSIntersectsRect
. But NSIntersectsRect
won't respect the rotation of rectangle. The points in structure are the points obtained after rotation.
Objecitve-C,C ++或C中的示例代码将是一个很大的帮助。
Sample code in Objecitve-C ,C++ or C will be a great help.
推荐答案
一个简单的方法是检查一个矩形的每个顶点是否在一个边缘的相同和外侧,反之亦然。有关更快和更通用的方法,请参阅
http://gpwiki.org/index.php/Polygon_Collision 和 http://cgm.cs.mcgill.ca /~godfried/teaching/cg-projects/97/Plante/CompGeomProject-EPlante/algorithm.html
One simple way is to check whether every vertex of one rectangle is on the same and exterior side of an edge of the one, and vice-versa. For faster and more general methods, see http://gpwiki.org/index.php/Polygon_Collision and http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Plante/CompGeomProject-EPlante/algorithm.html
这篇关于旋转的2d矩形交叉点检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!