🔒 Locked
fast rectangle intersection
Advertisement
Original Post
Are these axis-aligned boxes, or can they be rotated?
In the case of axis-aligned ones, there are at most four checks you need to perform:
1. Check if box A is completely to the left of box B (a.left <= b.right). If so, then quit the process: they don't intersect.
2. Otherwise, check if it's completely to the right (a.right >= b.left). If so, quit the process.
3. If not, check if it's completely above box B (a.bottom >= b.top). If so, quit.
4. If not, check if it's completely beneath box B (a.top <= b.bottom). If so, quit.
If not, then the boxes intersect.
This method is in fact a simplification of the Separating Axis Theorem.
In the case of axis-aligned ones, there are at most four checks you need to perform:
1. Check if box A is completely to the left of box B (a.left <= b.right). If so, then quit the process: they don't intersect.
2. Otherwise, check if it's completely to the right (a.right >= b.left). If so, quit the process.
3. If not, check if it's completely above box B (a.bottom >= b.top). If so, quit.
4. If not, check if it's completely beneath box B (a.top <= b.bottom). If so, quit.
If not, then the boxes intersect.
This method is in fact a simplification of the Separating Axis Theorem.
Yes they are.
I tried a different approach, than that you mentioned. I checked for if x,y points of rectangle are inside of another, and if so then they intersect. But that wasn't perfect. Also your approach is simplier.
And if boxes aren't axis-aligned? How can I check that?
Also how can I check if right-angled triangle and axis-aligned box intersect?
I tried a different approach, than that you mentioned. I checked for if x,y points of rectangle are inside of another, and if so then they intersect. But that wasn't perfect. Also your approach is simplier.
And if boxes aren't axis-aligned? How can I check that?
Also how can I check if right-angled triangle and axis-aligned box intersect?
Quote:As Captain P mentioned, the axis-aligned rect test is a special case of the separating axis theorem. The generalized version of the SAT test can be used for both the oriented box and triangle vs. box tests you mention above.
Original post by streamer
And if boxes aren't axis-aligned? How can I check that?
Also how can I check if right-angled triangle and axis-aligned box intersect?
Quote:
Original post by jyk Quote:As Captain P mentioned, the axis-aligned rect test is a special case of the separating axis theorem. The generalized version of the SAT test can be used for both the oriented box and triangle vs. box tests you mention above.
Original post by streamer
And if boxes aren't axis-aligned? How can I check that?
Also how can I check if right-angled triangle and axis-aligned box intersect?
I'm sorry but can I have some link with teoretic part on separating axis theorem, or in better case some c++ code? I'll apreciate that.
Thanks in advance.
I've found N Tutorials - Collision Detection and Response to be a very insightfull article. It even contains Flashy examples to visualize the theory.
Quote:
Original post by Captain P
I've found N Tutorials - Collision Detection and Response to be a very insightfull article. It even contains Flashy examples to visualize the theory.
That was what I searched for. Thank you very much!!!!
Quote:Which, incidentally, is the very first hit returned by Google :)
Original post by Captain P
I've found N Tutorials - Collision Detection and Response to be a very insightfull article.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement