-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathExample10.cs
89 lines (72 loc) · 2.42 KB
/
Example10.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace TriangleNet.Examples
{
using System;
using System.Collections.Generic;
using System.Linq;
using TriangleNet.Geometry;
/// <summary>
/// Troubleshooting: finding degenerate boundary triangles.
/// </summary>
public class Example10 : IExample
{
public bool Run(bool print = false)
{
var pts = new List<Vertex>
{
// The 4 corners of the rectangle.
new Vertex(1.5, 1.0),
new Vertex(1.5, -1.0),
new Vertex(-1.5, -1.0),
new Vertex(-1.5, 1.0),
// The edge midpoints.
new Vertex(0.0, 1.0),
new Vertex(0.0, -1.0),
new Vertex(1.5, 0.0),
new Vertex(-1.5, 0.0)
};
var r = new Random(78403);
// The original rectangle.
var poly = Rotate(pts, 0);
for (int i = 0; i < 10; i++)
{
var mesh = poly.Triangulate();
var list = MeshValidator.GetDegenerateBoundaryTriangles(mesh);
if (print && list.Any())
{
Console.WriteLine("Iteration {0}: found {1} degenerate triangle(s) of {2}.",
i, list.Count(), mesh.Triangles.Count);
foreach (var t in list)
{
Console.WriteLine(" [{0} {1} {2}]",
t.GetVertexID(0),
t.GetVertexID(1),
t.GetVertexID(2));
}
}
// Random rotation.
poly = Rotate(pts, Math.PI * r.NextDouble());
}
return true;
}
/// <summary>
/// Rotate given point set around the origin.
/// </summary>
private static IPolygon Rotate(List<Vertex> points, double radians)
{
var poly = new Polygon(points.Count);
int id = 0;
foreach (var p in points)
{
double x = p.X;
double y = p.Y;
double s = Math.Sin(radians);
double c = Math.Cos(radians);
double xr = c * x - s * y;
double yr = s * x + c * y;
poly.Points.Add(new Vertex(xr, yr) { ID = id++ });
}
return poly;
}
}
}