Skip to main content
GameDev.net gamedev.net
🔒 Locked

2d point in a projected bounding box

Started by bwhiting Aug 2, 2010 at 5:41 AM 5 replies 2k views
Original Post
bwhiting
bwhiting
HALLLOOOO

I am trying to implement some new ideas for 3d occlusion culling and one of them requires that I can test to see if a 2d point is within a projected (flat/2d) bounding box.

I know how to check for a point in a polygon but I don't think this is really the same as it often have redundant points in the middle.

So what I am after I suppose is an algorithm to find out if a 2d point is contained in a set of 2d points?



Anyone tried to do this or know if there is a simple solution?

Thanks.
LorenzoGatti
LorenzoGatti
Your post is quite incomprehensible.

Where do "2d" points appear in occlusion culling? Are you talking about screen-space techniques?

What are the "redundant points in the middle"? What middle are they in, and why are they redundant?

How is a "projected (flat/2d) bounding box" different from a generic convex polygon in a generic plane?
Omae Wa Mou Shindeiru
Adam_42
Adam_42
I presume the point and bounding box vertices are projected into 2D coordinates. That leaves a 4-6 sided polygon, with some internal lines, and a point.

What I'd suggest is using back face culling to eliminate the faces that you can ignore. That leaves you with 1-3 faces pointing at the camera. I'd then just iterate through those faces, testing each one against the point individually. It's probably not worth trying to make them into a single 2D polygon unless there's a lot of points that need testing against the one box.
bwhiting
bwhiting
apologies for my incomprehensibility.

Adam_42 is on the right track :)


yeah I'm talking screen space and I have managed to eliminate the points that are redundant by assigning each vertex in the BB a list of adjacent polys and then I can include them (the vertices) only if they have at least one adjacent back-facing poly and at least one front-facing poly too. (this worked like a charm).

then I used a point in polygon test to continue from there.



That said Adam_42's solution sounds much simpler. I guess it is probably faster too. Is there is a quick way to do a point in quad test as opposed to point in n-sided poly? Will have to do some more tests.

Cheers for replying.
bwhiting
bwhiting
good call, I'm trying out a few different methods in different scenarios so I'll try and see if the approximation is good enough for some situations (guessing it will be).
taz0010
taz0010
Doing a 2D point in polygon check is really, really fast. Fitting the polygon to an AABB and then checking against it won't be any faster. But if you're checking multiple points against the same region, then approximating with an AABB is faster.
Am I correct in assuming that the projection of a convex polyhedron onto a plane is also convex? The point-in-polygon check is a little faster if the polygon is known to be convex. There's actually a O(log(n)) solution (after O(n) preprocessing) but it's only worth it for polygons with larger numbers of sides.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.