Sign in to follow this  

Fastest point within OBB test

Recommended Posts

Original post by drvannostrand
Looking for the fastest boolean method to check if a point is within an OBB, in 2D. The OBB will always be a square, not a rectangle.
vector2 diff = point -;

std::fabs(dot(diff,box.axis[0])) <= box.extent &&
std::fabs(dot(diff,box.axis[1])) <= box.extent;
That should be plenty fast, I would think :)

Share this post

Link to post
Share on other sites
So you have a point P and a square as an OBB with center C, side length a and rotation angle alpha. To test if P is inside the square, you can calculate:
1) Move coordinate system so that C is in the origin: P1 = P - C
2) Rotate around the origin so that the square becomes axis aligned: P2 = M * P1, where M is the rotation matrix for -alpha
3) Check if the point is in the bounds: result = abs(P2.x) < a/2 && abs(P2.y) < a/2
If result is true, the point is inside the OBB.
Calculation costs are 2 additions, 2 subtractions and 4 multiplications.

Seems I have to type faster...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this