Sign in to follow this  
lordikon

Rectangle<->Frustum Intersection test?

Recommended Posts

I'm basically just trying to check if a flat quad rectangle lies within the view frustum or not. The rectangle is not axis-aligned, it can have any scale or transform (position, rotation). The current frustum information I have is just the 6 planes that make up the frustum, although if I truly need I could probably calculate the 8 corners of the frustum.

I searched all over google and most of the results seem to be plane checks rather than rectangles.

EDIT: I think I might have it. Let me know if this sounds like it would work:

Check each point on the rectangle against the frustum. If any point is in the frustum then it's in view. If no points are within the frustum check if any edge of the rectangle intersects any of the frustum planes. If any edges intersect a frustum plane then it's in view.

I think this will work, and I already have the algorithms for checking points against the frustum, so I should be able to use that algorithm and the fact that all the points are outside of the frustum to handle either case.

Share this post


Link to post
Share on other sites
If the rectangle is bigger than the frustum, you'll have problems as not only will no points be inside, but no lines will pass through since it's larger in all respects. If the rectangle-line check fails, try checking the frustum's lines for intersection with the rectangle.

Share this post


Link to post
Share on other sites
If you only check for those factors you will completely miss any quad that is larger than the frustum. A common way is to test if all points are on the same side of a single frustum plane. You will get false positives in some cases, but that's usually better than the other way around. If you want perfect results, you will probably end up checking for intersection in both ways. Don't just see if the polygon points/edges intersect the frustum, but also if the frustum edges intersect the polygon.

Edit: I really need to stop taking so much time when writing answers.

Share this post


Link to post
Share on other sites
There would have to be a huge speed bonus in calculation and not much speed increase in culling (if that's what this is for) to use your first method. That's a [i]lot[/i] of false positives :lol: In fact, wouldn't there [i]always [/i]be a plane in the frustum with the points on the same side?

Share this post


Link to post
Share on other sites
Hidden
There would have to be a huge speed bonus in calculation and not much speed increase in culling (if that's what this is for) to use your first method. That's a [i]lot[/i] of false positives :lol:

Share this post


Link to post
[quote name='Lonesome Ducky' timestamp='1311486692' post='4839489']
There would have to be a huge speed bonus in calculation and not much speed increase in culling (if that's what this is for) to use your first method. That's a [i]lot[/i] of false positives :lol: In fact, wouldn't there [i]always [/i]be a plane in the frustum with the points on the same side?
[/quote]

You're right. Replace "same side" of a plane with "outside" of a single plane, ie. all points are left/right/above/below/behind/beyond the frustum.

Share this post


Link to post
Share on other sites
Good stuff guys, thanks. I do believe that checking if all four points of the rectangle are on the outside of any of the planes then that will mean it's not colliding. Thanks!

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