Point in the OBB algorithm (oriented boundary)?

Given the center point, width, height and angle that make up the OBB, how can I find if the given point P is inside the OBB?

thank

+5
source share
2 answers

I suppose the wrinkle in your problem is that the bounding box can be rotated? If so, the simplest solution for me is to do all the calculations in a rotating coordinate plane centered on the center of the bounding box.

To calculate the coordinates of a 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 the angle should be measured, I will leave it to you since you did not specify)

, :

return (newy > centery - height / 2) && (newy < centery + height / 2) 
    && (newx > centerx - width / 2) && (newx < centerx + width / 2);
+8

( ) , .

-, .. xmin, xmax, ymin, ymax. xmin, xmax = xmid -+ width/2 ymin, ymax = ymid -+ height/2.

, .

0

All Articles