.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_curvature_directions.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_auto_examples_example_curvature_directions.py: .. _example_curvature_directions: =================================== example of curvature directions in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-18 .. code-block:: Python # Authors: Julien Lefevre # License: MIT # sphinx_gallery_thumbnail_number = 2 # importation of slam modules import slam.generate_parametric_surfaces as sgps import slam.curvature as scurv .. GENERATED FROM PYTHON SOURCE LINES 19-20 Create quadric mesh .. GENERATED FROM PYTHON SOURCE LINES 20-35 .. code-block:: Python nstep = 20 equilateral = True K = [1, 0.5] quadric_mesh = sgps.generate_quadric( K, nstep=[int(nstep), int(nstep)], equilateral=equilateral, ax=1, ay=1, random_sampling=False, ratio=0.2, random_distribution_type="gaussian", ) .. GENERATED FROM PYTHON SOURCE LINES 36-37 Compute principal directions of curvature .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python PrincipalCurvatures, PrincipalDir1, PrincipalDir2 \ = scurv.curvatures_and_derivatives(quadric_mesh) .. rst-class:: sphx-glr-script-out .. code-block:: none Calculating vertex normals .... Please wait Finished calculating vertex normals Calculating curvature tensors ... Please wait Finished Calculating curvature tensors Calculating Principal Components ... Please wait Finished Calculating principal components .. GENERATED FROM PYTHON SOURCE LINES 41-43 VISUALIZATION USING matplotlib ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 47-48 Visualization of vector fields with matplotlib .. GENERATED FROM PYTHON SOURCE LINES 48-88 .. code-block:: Python def visualize(mesh, vector_field, colors=None, params=None): """ Visualize a mesh and a vector field over it :param mesh: a mesh with n points :param vector_field: (n,3) array :param colors: (n,3) array :param params: params[0] is the length of the quivers :return: """ n = mesh.vertices.shape[0] if colors is None: colors = np.zeros((n, 3)) colors[:, 0] = 1 if params is None: params = [] params.append(0.1) ax = plt.figure().add_subplot(projection='3d') ax.plot_trisurf( mesh.vertices[:, 0], mesh.vertices[:, 1], mesh.vertices[:, 2], triangles=mesh.faces, shade=True, ) plt.quiver( np.array(mesh.vertices[:, 0]), np.array(mesh.vertices[:, 1]), np.array(mesh.vertices[:, 2]), vector_field[:, 0], vector_field[:, 1], vector_field[:, 2], length=params[0], colors=colors, ) return ax visualize(quadric_mesh, PrincipalDir1) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_example_curvature_directions_001.png :alt: example curvature directions :srcset: /auto_examples/images/sphx_glr_example_curvature_directions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.660 seconds) .. _sphx_glr_download_auto_examples_example_curvature_directions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_curvature_directions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_curvature_directions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_curvature_directions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_