判断2D平面内某点是否在某个旋转的矩形(OBB)内的算法
2014-07-08 17:58
417 查看
http://stackoverflow.com/questions/7328424/point-in-obb-oriented-bounding-box-algorithm
Given a center point, width, height and angle forming an OBB, how can I find if a given point P is inside the OBB?
I take it that the wrinkle in your problem is that the bounding box can be rotated? If so, the easiest solution to me seems to be to do all calculations in the rotated coordinate plane, centered on the center of the bounding box.
To calculate the coordinates of the point relative to these axes:
(you may need to adjust this depending on how angle is supposed to be measured, I'll leave that to you, since you didn't specify)
Then hit test, the normal way:
Given a center point, width, height and angle forming an OBB, how can I find if a given point P is inside the OBB?
I take it that the wrinkle in your problem is that the bounding box can be rotated? If so, the easiest solution to me seems to be to do all calculations in the rotated coordinate plane, centered on the center of the bounding box.
To calculate the coordinates of the point relative to these axes:
newy = sin(angle) * (oldy - centery) + cos(angle) * (oldx - centerx); newx = cos(angle) * (oldx - centerx) - sin(angle) * (oldy - centery);
(you may need to adjust this depending on how angle is supposed to be measured, I'll leave that to you, since you didn't specify)
Then hit test, the normal way:
return (newy > centery - height / 2) && (newy < centery + height / 2) && (newx > centerx - width / 2) && (newx < centerx + width / 2);
相关文章推荐
- 怎样判断平面上一个矩形和一个圆形是否有重叠?
- OpenVc判断矩形是否相交算法
- 算法:如何判断平面上的四个点是不是组成一个矩形
- 【原创】《矩阵的史诗级玩法》连载三:判断一个点是否在矩形内(支持带旋转的)
- 旋转矩形碰撞检测 OBB方向包围盒算法
- 矩形旋转碰撞,OBB方向包围盒算法实现
- 今天写了一个很简单的判断平面坐标系两线段是否相交的算法
- C语言平面几何6-判断线段是否与矩形范围有交集
- 判断两个矩形是否相交的算法
- 【算法】计算机图形学的一些经典小题:判断点在多边形内,随机生成三角形内的点,判断两个矩形是否相交等
- 判断一个点是否在旋转过任意角度的矩形内
- 判断findcontour找到的旋转矩形是否包含某个点的方法
- 矩形旋转碰撞,OBB方向包围盒算法实现
- 怎样判断平面上一个矩形和一个圆形是否有重叠?
- 矩形旋转碰撞,OBB方向包围盒算法实现
- 矩形旋转碰撞,OBB方向包围盒算法实现
- 经典算法 | 给定n个矩形,判断这些矩形是否在不重合的情况下组成一个大矩形的算法
- 判断两字符串是否互为旋转 -- 漫漫算法路 刷题篇
- 平面中判断点是否在某一三角形内算法 .
- 经典算法面试题目-判断s2是否是s1的旋转字符串(1.8)