Problem: Find contour lines of a triangulated surface
To find a contour lines of a triangulated surface, simply intersect each triangle of the surface with a plane parallel to the XY-plane.
Of course, arbitrary sections can be generated as well.
Solution using V#
- public static void ContourLineExample()
- {
- // Create a sample set of triangles. This requires the
- // ComputationalGeometry namespace! The following creates a
- // starfish-shaped structure based on the supershape formula:
- PointSet ps = SamplePoints.SupershapeStarfish(10000);
- dt.TriangulationPoints = ps;
- dt.Triangulate();
- List<Triangle> triangles = dt.GetTriangles();
- // Let's say, we would like to see the contour lines
- // z = 0.05, z = 0.10, z = 0.15 and z = 0.20:
- // Compute the contour edges
- foreach ( Triangle t in triangles )
- {
- contourEdges.Add(t.Intersect3d(pl005));
- contourEdges.Add(t.Intersect3d(pl010));
- contourEdges.Add(t.Intersect3d(pl015));
- contourEdges.Add(t.Intersect3d(pl020));
- }
- // visualize: ---------------------------------------------------------
- // make a scene:
- // Make a layer for the contour lines
- // Make a layer for the triangles
- // Add the contou lines to the scene
- sc.Add(contourEdges, cLayer);
- sc.Add(triangles, tLayer);
- // output the scene as dxf
- sc.WriteDxf(@"c:\contour_lines.dxf");
- }


