.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_polygon.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_polygon.py: Polygon meshing =============== .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: Python import copy import math import openturns as ot import openturns.viewer as otv import otmeshing .. GENERATED FROM PYTHON SOURCE LINES 14-15 Define a non-convex regular polygon from a set of points .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: Python 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]) .. GENERATED FROM PYTHON SOURCE LINES 25-26 Repeat the first point to draw the closed polygon .. GENERATED FROM PYTHON SOURCE LINES 26-33 .. code-block:: Python polyline_closed = copy.copy(polyline) polyline_closed.append(polyline[0]) graph = ot.Graph("Polygon", "X1", "X2", True, '') curve = ot.Curve(polyline_closed) graph.add(curve) view = otv.View(graph) .. image-sg:: /auto_examples/images/sphx_glr_plot_polygon_001.png :alt: Polygon :srcset: /auto_examples/images/sphx_glr_plot_polygon_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-35 Triangulate the polygon .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: Python mesher = otmeshing.PolygonMesher() triangulation = mesher.build(polyline) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Plot triangulation .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python graph = triangulation.draw() graph.setLegendPosition("upper left") graph.setTitle("Polygon triangulation") view = otv.View(graph) .. image-sg:: /auto_examples/images/sphx_glr_plot_polygon_002.png :alt: Polygon triangulation :srcset: /auto_examples/images/sphx_glr_plot_polygon_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-47 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_examples_plot_polygon.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_polygon.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_polygon.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_polygon.zip `