Examples

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#

  1.    public static void ContourLineExample()
  2.     {
  3.         // Create a sample set of triangles. This requires the
  4.         // ComputationalGeometry namespace! The following creates a
  5.         // starfish-shaped structure based on the supershape formula:
  6.         PointSet ps = SamplePoints.SupershapeStarfish(10000);
  7.         DelaunayTriangulation2d dt = new DelaunayTriangulation2d();
  8.         dt.TriangulationPoints = ps;
  9.         dt.Triangulate();
  10.         List<Triangle> triangles = dt.GetTriangles();
  11.  
  12.         // Let's say, we would like to see the contour lines
  13.         // z = 0.05, z = 0.10, z = 0.15 and z = 0.20:
  14.         Plane pl005 = new Plane(new Point(0, 0, 0.05), new Vector3d(0, 0, 1));
  15.         Plane pl010 = new Plane(new Point(0, 0, 0.10), new Vector3d(0, 0, 1));
  16.         Plane pl015 = new Plane(new Point(0, 0, 0.15), new Vector3d(0, 0, 1));
  17.         Plane pl020 = new Plane(new Point(0, 0, 0.20), new Vector3d(0, 0, 1));
  18.  
  19.         // Compute the contour edges
  20.         List<Edge> contourEdges = new List<Edge>();
  21.         foreach ( Triangle t in triangles )
  22.         {
  23.             contourEdges.Add(t.Intersect3d(pl005));
  24.             contourEdges.Add(t.Intersect3d(pl010));
  25.             contourEdges.Add(t.Intersect3d(pl015));
  26.             contourEdges.Add(t.Intersect3d(pl020));
  27.         }
  28.  
  29.         // visualize: ---------------------------------------------------------
  30.         // make a scene:
  31.         Scene sc = new Scene();
  32.  
  33.         // Make a layer for the contour lines
  34.         Scene.Layer cLayer = new Scene.Layer("Contour_lines", 2);
  35.        
  36.         // Make a layer for the triangles
  37.         Scene.Layer tLayer = new Scene.Layer("Delaunay_Triangles", 1);
  38.  
  39.         // Add the contou lines to the scene
  40.         sc.Add(contourEdges, cLayer);
  41.         sc.Add(triangles, tLayer);
  42.  
  43.         // output the scene as dxf
  44.         sc.WriteDxf(@"c:\contour_lines.dxf");
  45.     }

Output

Fig. 1: contour lines of a triangulated surface.
Fig. 2: Top view on contour lines.

<< back