Jump to content
• Advertisement

# 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

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. Thanks in advance.

#### Share this post

##### Share on other sites
Advertisement
Quote:
 Original post by drvannostrandLooking 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;return    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

##### 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.

Edit:
Seems I have to type faster...

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5
• Advertisement

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631424
• Total Posts
3000008
×

## 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!