# point is in a mesh?

This topic is 5468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
yes. it's a good idea!
but it can be convex and non-convex too.

|lo|

##### 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 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 on other sites
How can I cast a ray, and count the intersects? (i'm not experienced in raycasting)

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

D3DXIntersect()

Quote:
 Original post by sirobAs 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 on other sites
thank you all!
THX THX THX

it works!
thx :))))

good bye, lo. :))

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 10
• 9
• 15
• 22