.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_cylinder.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_cylinder.py: Cylinder meshing ================ .. GENERATED FROM PYTHON SOURCE LINES 7-13 In this example we will see how to define generalized cylindric shapes, how we to generate their meshes and compute their intersection mesh. The Cylinder objects are distinct from their mesh and CloudMesher objects will allow to compute their meshes. Then knowing their meshes are convex by definition we can use the IntersectionMesher to compute the intersection. .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python import openturns as ot import openturns.viewer as otv import otmeshing as otm .. GENERATED FROM PYTHON SOURCE LINES 20-21 Define a 3D cylinder with a disc-shaped base .. GENERATED FROM PYTHON SOURCE LINES 21-40 .. code-block:: Python N = 10 M = 2 dim = 3 print("Build cylinder 1") xc1 = 0.0 yc1 = 0.0 R1 = 1.0 H1 = 4.0 f1 = ot.SymbolicFunction( ["x", "y"], [f"(x-({xc1}))^2+(y-({yc1}))^2"] ) levelSet1 = ot.LevelSet(f1, ot.LessOrEqual(), R1**2) base1 = ot.LevelSetMesher([N] * 2).build( levelSet1, ot.Interval([xc1 - R1, yc1 - R1], [xc1 + R1, yc1 + R1]) ) extension1 = ot.Interval([-H1 / 2] * (dim - 2), [H1 / 2] * (dim - 2)) injection1 = list(range(2, dim)) cyl1 = otm.Cylinder(base1, extension1, injection1, M) .. rst-class:: sphx-glr-script-out .. code-block:: none Build cylinder 1 .. GENERATED FROM PYTHON SOURCE LINES 41-42 Define an other cylinder in another direction .. GENERATED FROM PYTHON SOURCE LINES 42-57 .. code-block:: Python yc2 = 0.8 zc2 = 0.0 R2 = 0.5 H2 = 4.0 f2 = ot.SymbolicFunction( ["y", "z"], [f"(y-({yc2}))^2+(z-({zc2}))^2"] ) levelSet2 = ot.LevelSet(f2, ot.LessOrEqual(), R2**2) base2 = ot.LevelSetMesher([N] * 2).build( levelSet2, ot.Interval([yc2 - R2, zc2 - R2], [yc2 + R2, zc2 + R2]) ) extension2 = ot.Interval([-H2 / 2] * (dim - 2), [H2 / 2] * (dim - 2)) injection2 = [0] + list(range(3, dim)) cyl2 = otm.Cylinder(base2, extension2, injection2, M) .. GENERATED FROM PYTHON SOURCE LINES 58-59 Compute the mesh of both cylinders .. GENERATED FROM PYTHON SOURCE LINES 59-63 .. code-block:: Python method = otm.CloudMesher.BASIC mesh1 = otm.CloudMesher(method).build(cyl1.getVertices()) mesh2 = otm.CloudMesher(method).build(cyl2.getVertices()) .. GENERATED FROM PYTHON SOURCE LINES 64-65 Plot cylinder1 .. GENERATED FROM PYTHON SOURCE LINES 65-73 .. code-block:: Python shading = False thetaX, thetaY, thetaZ = 6.1, 2.7, 3.3 drawEdge = True graph1 = mesh1.draw3D(drawEdge, thetaX, thetaY, thetaZ, shading) graph1.setLegendPosition("upper left") graph1.setTitle("Cylinder1 mesh") view = otv.View(graph1) .. image-sg:: /auto_examples/images/sphx_glr_plot_cylinder_001.png :alt: Cylinder1 mesh :srcset: /auto_examples/images/sphx_glr_plot_cylinder_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 74-75 Plot cylinder2 .. GENERATED FROM PYTHON SOURCE LINES 75-80 .. code-block:: Python graph2 = mesh2.draw3D(drawEdge, thetaX, thetaY, thetaZ, shading) graph2.setLegendPosition("upper left") graph2.setTitle("Cylinder1 mesh") view = otv.View(graph2) .. image-sg:: /auto_examples/images/sphx_glr_plot_cylinder_002.png :alt: Cylinder1 mesh :srcset: /auto_examples/images/sphx_glr_plot_cylinder_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 81-82 Compute the intersection, we know both meshes are convex by definition .. GENERATED FROM PYTHON SOURCE LINES 82-84 .. code-block:: Python inter12 = otm.IntersectionMesher().buildConvex([mesh1, mesh2]) .. GENERATED FROM PYTHON SOURCE LINES 85-86 Plot intersection .. GENERATED FROM PYTHON SOURCE LINES 86-91 .. code-block:: Python graph = inter12.draw3D(drawEdge, thetaX, thetaY, thetaZ, shading) graph.setLegendPosition("upper left") graph.setTitle("Cylinder intersection") view = otv.View(graph) .. image-sg:: /auto_examples/images/sphx_glr_plot_cylinder_003.png :alt: Cylinder intersection :srcset: /auto_examples/images/sphx_glr_plot_cylinder_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 92-93 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_examples_plot_cylinder.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_cylinder.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_cylinder.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_cylinder.zip `