Fast intersection between Line and Mesh 🗲

Revised for version 12. viewportLayout1 is of type Model.

Revised for version 2022. viewportLayout1 is of type Design.


From Eyeshot version 12 and beyond, Line/Mesh intersection computation speed can be improved using the Mesh.BuildOctree() method.

The 3D space will be partitioned recursively in octants until the maxNumTriangles threshold is reached.

ReadSTL rs = new ReadSTL("bunny.stl");

Mesh mesh = (Mesh)rs.Entities[0];
viewportLayout1.Entities.Add(mesh, Color.Beige);
Line line = new Line(new Point3D(-80, -15, 40), new Point3D(80, -15, 30));
viewportLayout1.Entities.Add(line, Color.Red);

mesh.BuildOctree(); // builds octree data structure

Segment3D segment = new Segment3D(line.StartPoint, line.EndPoint);
IList<HitTriangle> trianglesHit = mesh.FindClosestTriangle(null, segment);

foreach (HitTriangle triangle in trianglesHit) 
   viewportLayout1.Entities.Add(new devDept.Eyeshot.Entities.Point(triangle.IntersectionPoint, 4), Color.Red);

Version 2022 and following

From version 2022 and beyond, this computation could be performed furthermore from geometric Kernel directly, with the following instructions:

GMesh geoMesh;

[...]// gets GMesh object

Octree octree = new Octree(geoMesh); // gets octree data structure from GMesh primitive

Segment3D segment = new Segment3D(new Point3D(-80, -15, 40), new Point3D(80, -15, 30));
SortedList<double, HitTriangle> triList = new SortedList<double, HitTriangle>();
octree.FindClosestTriangle(segment, null, triList);

IList<HitTriangle> trianglesHit = triList.Values;
Was this article helpful?
1 out of 2 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.