public void TestEquilateralTriangles() { double sqrt3 = Math.Sqrt(3); var vertices = new List <Vertex>() { new Vertex(0.0, 0.0) { ID = 0 }, new Vertex(1.0, sqrt3) { ID = 1 }, new Vertex(2.0, 0.0) { ID = 2 }, new Vertex(3.0, sqrt3) { ID = 3 } }; var mesh = new Dwyer().Triangulate(vertices, new Configuration()); var quality = new QualityMeasure(mesh); Assert.AreEqual(quality.AreaMinimum, quality.AreaMaximum); Assert.AreEqual(1.0, quality.AlphaMinimum); Assert.AreEqual(1.0, quality.AlphaMaximum); Assert.AreEqual(1.0, quality.Q_Minimum); Assert.AreEqual(1.0, quality.Q_Maximum); }
public void HandleMeshChange(Mesh mesh) { // New mesh stats lbNumVert.Text = statistic.Vertices.ToString(); lbNumSeg.Text = statistic.ConstrainedEdges.ToString(); lbNumTri.Text = statistic.Triangles.ToString(); // Update statistics tab angleHistogram1.SetData(statistic.MinAngleHistogram, statistic.MaxAngleHistogram); lbAreaMin.Text = Util.DoubleToString(statistic.SmallestArea); lbAreaMax.Text = Util.DoubleToString(statistic.LargestArea); lbEdgeMin.Text = Util.DoubleToString(statistic.ShortestEdge); lbEdgeMax.Text = Util.DoubleToString(statistic.LongestEdge); lbAngleMin.Text = Util.AngleToString(statistic.SmallestAngle); lbAngleMax.Text = Util.AngleToString(statistic.LargestAngle); // Update quality if (quality == null) { quality = new QualityMeasure(); } quality.Update(mesh); lbQualAlphaMin.Text = Util.DoubleToString(quality.AlphaMinimum); lbQualAlphaAve.Text = Util.DoubleToString(quality.AlphaAverage); lbQualAspectMin.Text = Util.DoubleToString(quality.Q_Minimum); lbQualAspectAve.Text = Util.DoubleToString(quality.Q_Average); }
public static bool Run(bool print = false) { // Generate mesh. var mesh = CreateMesh(); // The ideal area if triangles were equilateral. var area = Math.Sqrt(3) / 4 * h * h; var quality = new QualityMeasure(mesh); if (print) { Console.WriteLine($" Ideal area: {area}"); Console.WriteLine($" Min. area: {quality.AreaMinimum}"); Console.WriteLine($" Max. area: {quality.AreaMaximum}"); Console.WriteLine($" Avg. area: {quality.AreaTotal / mesh.Triangles.Count}"); SvgImage.Save(mesh, "example-4.svg", 500); } return(quality.AreaMinimum < area && quality.AreaMaximum > area); }
public static Mesh RefineRegions() { // Generate the input geometry. var poly = new Polygon(); var center = new Point(0, 0); // Three concentric circles. poly.Add(Example2.Circle(1.0, center, 0.1, 1), center); poly.Add(Example2.Circle(2.0, center, 0.1, 2)); poly.Add(Example2.Circle(3.0, center, 0.3, 3)); // Define regions. poly.Regions.Add(new RegionPointer(1.5, 0.0, 1)); poly.Regions.Add(new RegionPointer(2.5, 0.0, 2)); // Set quality and constraint options. var options = new ConstraintOptions() { ConformingDelaunay = true }; var quality = new QualityOptions() { MinimumAngle = 25.0 }; // Generate mesh. var mesh = (Mesh)poly.Triangulate(options, quality); var smoother = new SimpleSmoother(); // Smooth mesh and re-apply quality options. smoother.Smooth(mesh); mesh.Refine(quality); // Calculate mesh quality var statistic = new QualityMeasure(); statistic.Update(mesh); // Use the minimum triangle area for region refinement double area = 1.75 * statistic.AreaMinimum; foreach (var t in mesh.Triangles) { // Set area constraint for all triangles in region 1 if (t.Label == 1) { t.Area = area; } } // Use per triangle area constraint for next refinement quality.VariableArea = true; // Refine mesh to meet area constraint. mesh.Refine(quality); // Smooth once again. smoother.Smooth(mesh); return(mesh); }