Sign in to follow this  

point is in a mesh?

This topic is 4821 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

Hi all! I would like to ask that how can I become aware of a given point is in a mesh. The mesh is loaded from an .x file. for example I load a box, its coordinates are A(0,0,0) B(0,1,0) C(1,1,0) D(1,0,0) E(0,0,1) F(0,1,1) G(1,1,1) H(1,0,1) and how can i check that P(0.5, 0.5, 0.5) is in the box? it's easy in this situation, but i don't know the figure of the mesh. thx, lo

Share this post


Link to post
Share on other sites
If your mesh is convex then if the point lies in the negative half space of all the mesh triangle planes (assuming your tri normals point outwards) then it lies inside the mesh.

Share this post


Link to post
Share on other sites
After you've done the coarser test against bounding volume and any spatial organisation structure, I think the "Crossings Test" (based on the Jordan Curve Theorem) should work:

1) cast a ray from the point in an arbitrary direction.

2) count how many polygons the ray intersects.

3) if the count is odd, the point is inside the mesh. If the count is even, the point is outside the mesh.


It works fine in concave situations. The only caveat is ensuring the ray doesn't intersect a vertex.

Share this post


Link to post
Share on other sites
As for S1CA's method, this would only work assuming all faces are indeed part of the mesh's outer sorrounding - but I've seen meshes with faces inside them (can't possibly think why - but I have).

IF the mesh does have faces inside it, you might get incorrect results.

Share this post


Link to post
Share on other sites
Quote:
Original post by lo
How can I cast a ray, and count the intersects? (i'm not experienced in raycasting)


D3DXIntersect()



Quote:
Original post by sirob
As for S1CA's method, this would only work assuming all faces are indeed part of the mesh's outer sorrounding - but I've seen meshes with faces inside them (can't possibly think why - but I have).

IF the mesh does have faces inside it, you might get incorrect results.


Yep, good point; same goes for non-manifold meshes too. Checking the results of multiple rays to see if they tally would improve the accuracy significantly though in these cases (personally I'd simply make clean meshes a requirement of the export pipeline).

Share this post


Link to post
Share on other sites

This topic is 4821 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.

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