.. 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-14 .. code-block:: Python # Authors: Julien Lefevre # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 15-19 NOTE: there is no visualization tool in slam, but we provide at the end of this script exemplare code to do the visualization with an external solution ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. code-block:: Python # importation of slam modules import slam.generate_parametric_surfaces as sgps import slam.curvature as scurv .. GENERATED FROM PYTHON SOURCE LINES 25-26 Create quadric mesh .. GENERATED FROM PYTHON SOURCE LINES 26-41 .. 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 42-43 Compute principal directions of curvature .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. 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 47-96 VISUALIZATION USING EXTERNAL TOOLS ############################################################################## import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D ############################################################################# # Visualization of vector fields with matplotlib 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) fig = plt.figure() ax = Axes3D(fig) ax.plot_trisurf( mesh.vertices[:, 0], mesh.vertices[:, 1], mesh.vertices[:, 2], triangles=mesh.faces, shade=True, ) plt.quiver( mesh.vertices[:, 0], mesh.vertices[:, 1], mesh.vertices[:, 2], vector_field[:, 0], vector_field[:, 1], vector_field[:, 2], length=params[0], colors=colors, ) return fig visualize(quadric_mesh, PrincipalDir1) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.621 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 `_