.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/TPMS/graded_density.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_graded_density.py: Density grading =============== A gyroid sheet whose offset varies linearly along :math:`x`. The density does not vary linearly with the offset. .. GENERATED FROM PYTHON SOURCE LINES 8-49 .. code-block:: Python import numpy as np import numpy.typing as npt import pyvista as pv from microgen import Tpms from microgen.shape.surface_functions import gyroid def linear_graded_offset( x: npt.NDArray[np.float64], _: npt.NDArray[np.float64], __: npt.NDArray[np.float64], ) -> npt.NDArray[np.float64]: """Linearly graded offset.""" min_offset = 0.0 max_offset = 3.0 length = np.max(x) - np.min(x) return (max_offset - min_offset) * x / length + 0.5 * (min_offset + max_offset) def circular_graded_offset( x: npt.NDArray[np.float64], y: npt.NDArray[np.float64], _: npt.NDArray[np.float64], ) -> npt.NDArray[np.float64]: """Circularly graded offset.""" min_offset = 0.0 max_offset = 3.0 radius = 0.5 * (np.max(x) - np.min(x)) return (max_offset - min_offset) * (x**2 + y**2) / radius**2 + min_offset geometry = Tpms( surface_function=gyroid, offset=linear_graded_offset, repeat_cell=(5, 2, 1), resolution=30, ) sheet = geometry.sheet .. GENERATED FROM PYTHON SOURCE LINES 50-56 .. code-block:: Python plotter = pv.Plotter() plotter.add_mesh(sheet, smooth_shading=True, color="#ef7d2d") plotter.view_xy() plotter.enable_parallel_projection() plotter.show_axes() plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/TPMS/images/sphx_glr_graded_density_001.png :alt: graded density :srcset: /examples/TPMS/images/sphx_glr_graded_density_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/microgen/microgen/docs/examples/TPMS/images/sphx_glr_graded_density_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.982 seconds) .. _sphx_glr_download_examples_TPMS_graded_density.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: graded_density.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: graded_density.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: graded_density.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_