Jump to content
  • Advertisement
Sign in to follow this  

Fastest point within OBB test

This topic is 4209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 - box.center;

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!