Closed roadcad closed 1 year ago
Use a Polygon
and add the points and segments. Then use the polygon.Triangulate()
method to create the mesh.
Take a look at https://github.com/wo80/Triangle.NET/wiki/Polygon#using-segments and let me know, if anything is unclear.
Use a
Polygon
and add the points and segments. Then use thepolygon.Triangulate()
method to create the mesh.Take a look at https://github.com/wo80/Triangle.NET/wiki/Polygon#using-segments and let me know, if anything is unclear.
Thank you for quick response.
I tested code from link which you provide, and it works well. I am little confused with outher and inner box from your example. Actually, in my example you can see set of arbitrary points and one polyline (set of lines) inside that polygon - not outher or inner box. This is one example, but it is possible that be more that one set of lines (polyline).
Here's another simple example:
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Rendering.Text;
class Issue34
{
public static void Run()
{
var poly = new Polygon();
// The input point set.
var points = new Vertex[]
{
new Vertex(0d, 0d),
new Vertex(1d, 0d),
new Vertex(1d, 1d),
new Vertex(0d, 1d),
// These vertices are endpoints of segments.
new Vertex(.2d, .2d),
new Vertex(.4d, .6d),
new Vertex(.8d, .8d)
};
// Add all points at once.
poly.Points.AddRange(points);
// Now add segments. This is just a simple example. There are other
// poly.Add(segment, ...) overloads that might be better suited for
// your setup.
poly.Add(new Segment(points[4], points[5]));
poly.Add(new Segment(points[5], points[6]));
// IMPORTANT: use convex option. Otherwise all triangles will be eaten
// up since your input polygon has no outer boundary.
var mesh = poly.Triangulate(new ConstraintOptions() { Convex = true });
SvgImage.Save(mesh, "issue34.svg", 500, points: false);
}
}
Note that setting up the geometry this way, you'll have to deal with vertices and segments. There's no concept of lines / line strings in Triangle.NET.
You might also want to take a look at the following example: https://gist.github.com/wo80/fe9b40925cdfdafedad935457c4768dd
It introduces a Constraint
helper class and an extension method to simplify adding line strings to a polygon.
@wo80 Thank you very much for your help, second example explains everything and now it works very well.
Hello.
I am trying to triangulate set of points with constraint edges but could not to figure out how to do this with Triangle.net.
So, I hope that this is possible to do with this great library. It's attached example done in other software.
Thank you.