.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/BasicShapes/shapes.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_BasicShapes_shapes.py: Basic shapes ============ Create the elementary shapes of microgen with :func:`microgen.shape.new_geometry` and export them as a single CAD compound. Requires the CAD backend: ``pip install microgen[cad]``. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: Python import numpy as np import pyvista as pv from microgen.cad import make_compound from microgen.shape import new_geometry .. GENERATED FROM PYTHON SOURCE LINES 18-19 Shape parameters, keyed by shape name. .. GENERATED FROM PYTHON SOURCE LINES 19-39 .. code-block:: Python shapes = { "box": {"dim": (0.8, 0.8, 0.8)}, "sphere": {"radius": 0.5}, "capsule": {"height": 0.5, "radius": 0.3}, "cylinder": {"height": 0.5, "radius": 0.5}, "ellipsoid": {"radii": (0.5, 0.25, 0.3)}, "extrudedpolygon": { "list_corners": [ (0.5, 0), (0.25, 0.44), (-0.25, 0.44), (-0.5, 0), (-0.25, -0.44), (0.25, -0.44), (0.5, 0), ], "height": 0.5, }, } .. GENERATED FROM PYTHON SOURCE LINES 40-41 Place the shapes on a grid and build their CAD representation. .. GENERATED FROM PYTHON SOURCE LINES 41-59 .. code-block:: Python parts = [] n_col = 3 n_row = np.ceil(len(shapes) / n_col) for i, (shape, param_geom) in enumerate(shapes.items()): i_x = i % n_col i_y = i // n_col elem = new_geometry( shape=shape, center=(1.2 * (i_x - 0.5 * (n_col - 1)), -1.2 * (i_y - 0.5 * (n_row - 1)), 0), orientation=(90, 90, 90), param_geom=param_geom, ) parts.append(elem.generate_cad()) compound = make_compound(parts) stl_file = "shapes.stl" compound.export_stl(stl_file) .. GENERATED FROM PYTHON SOURCE LINES 60-61 Display the exported compound. .. GENERATED FROM PYTHON SOURCE LINES 61-62 .. code-block:: Python pv.read(stl_file).plot(smooth_shading=True, split_sharp_edges=True, color="#ef7d2d") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/BasicShapes/images/sphx_glr_shapes_001.png :alt: shapes :srcset: /examples/BasicShapes/images/sphx_glr_shapes_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/microgen/microgen/docs/examples/BasicShapes/images/sphx_glr_shapes_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.303 seconds) .. _sphx_glr_download_examples_BasicShapes_shapes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: shapes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: shapes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: shapes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_