点在OBB(定向边界框)算法? [英] Point in OBB (Oriented Bounding Box) algorithm?

查看:902
本文介绍了点在OBB(定向边界框)算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个中心点,宽度,高度和角度形成一个OBB,我如何找到一个给定的点P是否在OBB内?

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);

这篇关于点在OBB(定向边界框)算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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