.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/TPMS/tpms_shell.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_examples_TPMS_tpms_shell.py: Gyroid in a shell ================= A gyroid sheet inside a hollow box, as one implicit shape: the hollow box is a difference of two boxes, joined to the gyroid sheet with a union. One octant is removed to show the inside. The result is meshed by marching cubes, without the CAD backend. With ``pip install microgen[cad]``, ``Phase.from_shape(part).cad`` gives the OCCT shape for a STEP export. .. GENERATED FROM PYTHON SOURCE LINES 13-16 .. code-block:: Python from microgen import Box, Tpms, implicit_ops, surface_functions .. GENERATED FROM PYTHON SOURCE LINES 17-18 Outer 3 x 3 x 3 box, hollowed by subtracting an inner 2.8 x 2.8 x 2.8 cavity. .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python hollow_box = implicit_ops.box((3.0, 3.0, 3.0)) - implicit_ops.box((2.8, 2.8, 2.8)) .. GENERATED FROM PYTHON SOURCE LINES 21-22 27 gyroid cells filling the box, as a sheet 0.1 thick, clipped by the box. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python gyroid = Tpms(surface_function=surface_functions.gyroid, offset=0.3, repeat_cell=3) sheet = gyroid.as_sheet(thickness=0.1) & implicit_ops.box((2.9, 2.9, 2.9)) part = hollow_box | sheet .. GENERATED FROM PYTHON SOURCE LINES 27-28 Remove the octant facing the camera and mesh the field. .. GENERATED FROM PYTHON SOURCE LINES 28-37 .. code-block:: Python octant = Box(dim=(1.6, 1.6, 1.6), center=(0.8, 0.8, 0.8)) cut_part = part - octant mesh = cut_part.generate_surface_mesh( bounds=(-1.55, 1.55, -1.55, 1.55, -1.55, 1.55), resolution=150 ) mesh.save("tpms_shell.stl") print(f"{mesh.n_cells} triangles") mesh.plot(color="#ef7d2d", smooth_shading=True) .. image-sg:: /examples/TPMS/images/sphx_glr_tpms_shell_001.png :alt: tpms shell :srcset: /examples/TPMS/images/sphx_glr_tpms_shell_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 1168472 triangles .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.256 seconds) .. _sphx_glr_download_examples_TPMS_tpms_shell.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tpms_shell.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tpms_shell.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tpms_shell.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_