旋转2d矩形交叉检测

Rav*_*ash 2 c c++ graphics geometry objective-c

我有两个矩形任意放置,我有四个角点像

struct Rect
{
 NSPoint topLeft; 
 NSPoint topRight; 
 NSPoint bottomLeft; 
 NSPoint bottomRight; 
}
Run Code Online (Sandbox Code Playgroud)

我想检查2个矩形是否相交.我正在寻找类似的方法NSIntersectsRect.但NSIntersectsRect不会尊重矩形的旋转.结构中的点是旋转后获得的点.

Objecitve-C,C++或C中的示例代码将是一个很好的帮助.

lhf*_*lhf 5

一种简单的方法是检查一个矩形的每个顶点是否位于一个矩形的边缘的同一侧和外侧,反之亦然.有关更快更通用的方法,请参阅 http://gpwiki.org/index.php/Polygon_Collisionhttp://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Plante/CompGeomProject-EPlante /algorithm.html