.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/TPMS/graded_cell_size.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_cell_size.py: Cell size grading ================= A gyroid whose cell size follows a sigmoid transition along :math:`x`, from 2 to 4. Linear and Gaussian transitions are also given. .. GENERATED FROM PYTHON SOURCE LINES 8-73 .. 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 sigmoid( x: npt.NDArray[np.float64], start: float, end: float, ) -> npt.NDArray[np.float64]: """Sigmoid transition function.""" k = -0.4 # transition return start + (end - start) / (1 + np.exp(k * x)) def lerp( x: npt.NDArray[np.float64], start: float, end: float, ) -> npt.NDArray[np.float64]: """Linear interpolation function.""" t = (x - np.min(x)) / (np.max(x) - np.min(x)) return start + (end - start) * t def gaussian( x: npt.NDArray[np.float64], start: float, end: float, ) -> npt.NDArray[np.float64]: """Gaussian transition function.""" k = -0.02 return start + (end - start) * np.exp(k * x**2) def graded( x: npt.NDArray[np.float64], y: npt.NDArray[np.float64], z: npt.NDArray[np.float64], ) -> npt.NDArray[np.float64]: """Graded TPMS surface function.""" min_cell_size = 2 max_cell_size = 4 # dim_x = dim_y = dim_z = lerp(x, min_cell_size, max_cell_size) dim_x = dim_y = dim_z = sigmoid(x, min_cell_size, max_cell_size) # dim_x = dim_y = dim_z = gaussian(x, max_cell_size, min_cell_size) return gyroid( x=x * max_cell_size / dim_x, y=y * max_cell_size / dim_y, z=z * max_cell_size / dim_z, ) geometry = Tpms( surface_function=graded, offset=0.3, repeat_cell=(5, 2, 2), resolution=30, ) sheet = geometry.sheet .. GENERATED FROM PYTHON SOURCE LINES 74-80 .. 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() .. image-sg:: /examples/TPMS/images/sphx_glr_graded_cell_size_001.png :alt: graded cell size :srcset: /examples/TPMS/images/sphx_glr_graded_cell_size_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.599 seconds) .. _sphx_glr_download_examples_TPMS_graded_cell_size.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: graded_cell_size.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: graded_cell_size.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: graded_cell_size.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_