point is in a mesh?

Started by
6 comments, last by lo 19 years, 6 months ago
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
Advertisement
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.
[size="1"] [size="4"]:: SHMUP-DEV ::
yes. it's a good idea!
but it can be convex and non-convex too.

|lo|
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.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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.
Sirob Yes.» - status: Work-O-Rama.
How can I cast a ray, and count the intersects? (i'm not experienced in raycasting)
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).

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

thank you all!
THX THX THX

it works!
thx :))))

good bye, lo. :))

This topic is closed to new replies.

Advertisement