Note
Go to the end to download the full example code.
Polygon meshingΒΆ
import copy
import math
import openturns as ot
import openturns.viewer as otv
import otmeshing
Define a non-convex regular polygon from a set of points
polyline = []
n = 20
for i in range(n):
r = 2.0 + i % 2
theta = i * 2.0 * math.pi / n
x = r * math.cos(theta)
y = r * math.sin(theta)
polyline.append([x, y])
Repeat the first point to draw the closed polygon

Triangulate the polygon
mesher = otmeshing.PolygonMesher()
triangulation = mesher.build(polyline)
Plot triangulation
graph = triangulation.draw()
graph.setLegendPosition("upper left")
graph.setTitle("Polygon triangulation")
view = otv.View(graph)
otmeshing