.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/Lattices/honeycomb.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_Lattices_honeycomb.py: Honeycomb ========= A honeycomb obtained by cutting hexagonal prisms out of a box with :func:`microgen.cut_phase_by_shape_list`, then meshed with gmsh. Requires the CAD backend: ``pip install microgen[cad]``. .. GENERATED FROM PYTHON SOURCE LINES 10-65 .. code-block:: Python import numpy as np import pyvista as pv from microgen import Box, ExtrudedPolygon, Phase, cut_phase_by_shape_list, mesh side_length = 2.5 # side in mm of the hexagon poly_height = 2.5 # height in mm of the hexagon theta = 30 * np.pi / 180 # half angle of the hexagone h0 = 0.5 * poly_height h1 = np.cos(theta) * side_length h2 = abs(np.sin(theta) * side_length) thickness = 30 # mm data_file = "honeycomb_seeds.data" seedList = np.genfromtxt(data_file, delimiter="\t") box = Box(dim=(thickness, 60, 60)) shapeList = [] for seed in seedList: poly = ExtrudedPolygon( center=(seed[0] - thickness, seed[1], seed[2]), list_corners=[ (0, h2 + h0), (h1, h0), (h1, -h0), (0, -h2 - h0), (-h1, -h0), (-h1, h0), (0, h2 + h0), ], height=thickness, ) shapeList.append(poly.generate_cad()) boxPhase = Phase.from_cad(box.generate_cad()) honeycomb = cut_phase_by_shape_list(phase_to_cut=boxPhase, shapes=shapeList) step_file = "honeycomb.step" stl_file = "honeycomb.stl" honeycomb.cad.export_step(step_file) honeycomb.cad.export_stl(stl_file) vtk_file = "honeycomb.vtk" mesh( mesh_file=step_file, list_phases=[honeycomb], size=1, order=1, output_file=vtk_file, ) .. GENERATED FROM PYTHON SOURCE LINES 66-67 .. code-block:: Python pv.read(vtk_file).plot(show_edges=True, color="#ef7d2d") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/Lattices/images/sphx_glr_honeycomb_001.png :alt: honeycomb :srcset: /examples/Lattices/images/sphx_glr_honeycomb_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/microgen/microgen/docs/examples/Lattices/images/sphx_glr_honeycomb_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 15.086 seconds) .. _sphx_glr_download_examples_Lattices_honeycomb.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: honeycomb.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: honeycomb.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: honeycomb.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_