该函数用于判断一个点是否在OBB中。
obb:一个包围盒对象,包括以下属性:
x:OBB的中心点的x坐标;y:OBB的中心点的y坐标;w:OBB的宽度;h:OBB的高度;angle:OBB的旋转角度(单位为弧度)。point:一个点对象,包括以下属性:
x:点的x坐标;y:点的y坐标。如果该点在OBB中,返回true;否则返回false。
point.x -= obb.x, point.y -= obb.y。x = point.x * cos(angle) + point.y * sin(angle), y = -point.x * sin(angle) + point.y * cos(angle)。abs(x) < w/2 && abs(y) < h/2。true;否则返回false。const obb = {x: 0, y: 0, w: 100, h: 50, angle: Math.PI/4};
const point1 = {x: 10, y: 10}; // 在OBB中
const point2 = {x: 100, y: 0}; // 不在OBB中
console.log(containsPoint(obb, point1)); // true
console.log(containsPoint(obb, point2)); // false