Update example 4 (related to issue #21)

This commit is contained in:
wo80
2022-07-19 01:38:14 +02:00
parent 164318fd8e
commit ea2599e7d1
3 changed files with 40 additions and 16 deletions
+26 -5
View File
@@ -6,6 +6,7 @@ namespace TriangleNet.Examples
using TriangleNet.Meshing;
using TriangleNet.Rendering.Text;
using TriangleNet.Smoothing;
using TriangleNet.Tools;
/// <summary>
/// Triangulate a polygon with hole with maximum area constraint, followed by mesh smoothing.
@@ -17,15 +18,33 @@ namespace TriangleNet.Examples
// Generate mesh.
var mesh = CreateMesh();
if (print) SvgImage.Save(mesh, "example-4.svg", 500);
if (print)
{
// The ideal area if triangles were equilateral.
var area = Math.Sqrt(3) / 4 * h * h;
var quality = new QualityMeasure(mesh);
Console.WriteLine($" Ideal area: {area}");
Console.WriteLine($" Min. area: {quality.AreaMinimum}");
Console.WriteLine($" Max. area: {quality.AreaMaximum}");
SvgImage.Save(mesh, "example-4.svg", 500);
}
return mesh.Triangles.Count > 0;
}
// The boundary segment size of the input geometry.
const double h = 0.2;
// Parameter to relax the maximum area constraint.
const double relax = 1.45;
public static IMesh CreateMesh()
{
// Generate the input geometry.
var poly = Example3.CreatePolygon();
var poly = Example3.CreatePolygon(h);
// Since we want to do CVT smoothing, ensure that the mesh
// is conforming Delaunay.
@@ -35,9 +54,11 @@ namespace TriangleNet.Examples
// angle, since smoothing will improve the triangle shapes).
var quality = new QualityOptions()
{
// The boundary segments have a length of 0.2, so we set a
// maximum area constraint assuming equilateral triangles.
MaximumArea = (Math.Sqrt(3) / 4 * 0.2 * 0.2) * 1.45
// Given the boundary segment size, we set a maximum
// area constraint assuming equilateral triangles. The
// relaxation parameter is chosen to reduce the deviation
// from this ideal value.
MaximumArea = (Math.Sqrt(3) / 4 * h * h) * relax
};
// Generate mesh using the polygons Triangulate extension method.
+1 -1
View File
@@ -21,7 +21,7 @@ namespace TriangleNet.Examples
// Generate the input geometry.
poly.Add(Generate.Rectangle(0.0, 0.0, 1.0, 1.0));
// Set minimum angle quality option, ignoring holes.
// Set user test function.
var quality = new QualityOptions()
{
UserTest = MaxEdgeLength
+13 -10
View File
@@ -2,23 +2,26 @@
namespace TriangleNet
{
using System;
using System.Linq;
using TriangleNet.Examples;
class Program
{
static void Main(string[] args)
{
Check("Example 1", Example1.Run());
Check("Example 2", Example2.Run());
Check("Example 3", Example3.Run());
Check("Example 4", Example4.Run());
Check("Example 5", Example5.Run());
Check("Example 6", Example6.Run());
Check("Example 7", Example7.Run());
Check("Example 8", Example8.Run());
bool print = args.Contains("--print");
Check("Example 1", Example1.Run(print));
Check("Example 2", Example2.Run(print));
Check("Example 3", Example3.Run(print));
Check("Example 4", Example4.Run(print));
Check("Example 5", Example5.Run(print));
Check("Example 6", Example6.Run(print));
Check("Example 7", Example7.Run(print));
Check("Example 8", Example8.Run(print));
Check("Example 9", Example9.Run());
Check("Example 10", Example10.Run());
Check("Example 11", Example11.Run());
Check("Example 10", Example10.Run(print));
Check("Example 11", Example11.Run(print));
}
static void Check(string item, bool success)