DesignEngrLab / TVGL

Tessellation and Voxelization Geometry Library
http://designengrlab.github.io/TVGL/
MIT License
58 stars 17 forks source link

Whether a point is inside a 3d polygon #63

Closed mikhail-rozum closed 6 months ago

mikhail-rozum commented 7 months ago

Hello! I'm new here. I have *.stl file with some model. I need to find all the points inside this model. I found a question that refers to MiscFunctions.cs file. Firstly, I read all the vertices from file and create convex hull.

var result = StlHelper.ReadFile(stlPath); // List<Vertex>
var hull = ConvexHull.Create(result);
var tessellatedSolid = new TessellatedSolid(...); // <---

Later I try to use MiscFunctions.IsPointInsideSolid method that required TessellatedSolid parameter. Is it right? Is there an example of checking whether a point is inside a 3d polygon?

micampbell commented 7 months ago

for speed purposes it often makes sense to first check if the point is inside the convex hull. If it is then check if the point is inside the solid. Coincidentally both of these methods have been improved fairly recently (and some of the classes have changed names). But for simplicity, MiscFunctions.IsPointInsideSolid will in fact tell you if a point is in the a complex (not necessarily convex) 3d model.


IO.Open(Path.Combine(inputFolder, "bunny.stl"), out TessellatedSolid bunny);
Presenter.ShowAndHang(bunny);
var point = new Vector3(0, 0, 0);
//var point = bunny.Center;
if ( MiscFunctions.IsPointInsideSolid(bunny, point))
     Console.WriteLine("Inside");
else
   Console.WriteLine("Outside");`
mikhail-rozum commented 6 months ago

for speed purposes it often makes sense to first check if the point is inside the convex hull. If it is then check if the point is inside the solid. Coincidentally both of these methods have been improved fairly recently (and some of the classes have changed names). But for simplicity, MiscFunctions.IsPointInsideSolid will in fact tell you if a point is in the a complex (not necessarily convex) 3d model.

IO.Open(Path.Combine(inputFolder, "bunny.stl"), out TessellatedSolid bunny);
Presenter.ShowAndHang(bunny);
var point = new Vector3(0, 0, 0);
//var point = bunny.Center;
if ( MiscFunctions.IsPointInsideSolid(bunny, point))
     Console.WriteLine("Inside");
else
   Console.WriteLine("Outside");`

Thank you so much!

mikhail-rozum commented 6 months ago

The question is answered