旋转的2d矩形交叉点检测 [英] Rotated 2d rectangle intersection detection

查看:530
本文介绍了旋转的2d矩形交叉点检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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 NSIntersectsRectwon'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屋!

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