mhogg / pyoctree

Octree structure containing a 3D triangular mesh model
MIT License
86 stars 19 forks source link

Determine if a point is OUTSIDE or INSIDE a mesh #33

Closed DavideBassano closed 5 years ago

DavideBassano commented 6 years ago

Hello,

I need to determine if a given point is inside or outside a triangular mesh.

My idea is to draw a random line from that point: if the line and the normal of intersected face are in the same direction that means that I'm inside the mesh.

Is there a smarter way to do it?

Thanks, Cheers,

Davide Bassano

mhogg commented 6 years ago

Hi Davide,

I haven't built this functionality into pyoctree. But you could do it by picking a point outside the bounds of the octree and then creating a ray from this point to your point of interest, and perhaps extending it even further. Pyoctree will find all the intersections for you and tells you if the ray is entering or leaving the shape at each. If your point lies between an entering and exit point, then your point of interest will be inside the shape.

Alternatively, perhaps another package like trimesh may be more suitable. If you read the feature list in the readme, it does what you want.

Cheers, Michael

DavideBassano commented 5 years ago

Thanks, it worked