.. 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 Click :ref:`here ` 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-15 .. code-block:: default # Authors: Julien Lefevre # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 16-17 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 17-25 .. code-block:: default import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import slam.generate_parametric_surfaces as sgps import slam.curvature as scurv .. GENERATED FROM PYTHON SOURCE LINES 26-27 Visualization of vector fields with matplotlib .. GENERATED FROM PYTHON SOURCE LINES 27-69 .. code-block:: default 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 .. GENERATED FROM PYTHON SOURCE LINES 70-71 Create quadric mesh .. GENERATED FROM PYTHON SOURCE LINES 71-87 .. code-block:: default 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 88-89 Compute principal directions of curvature .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: default PrincipalCurvatures, PrincipalDir1, PrincipalDir2 = scurv.curvatures_and_derivatives( quadric_mesh ) .. rst-class:: sphx-glr-script-out 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 95-96 Visualization .. GENERATED FROM PYTHON SOURCE LINES 96-99 .. code-block:: default visualize(quadric_mesh, PrincipalDir1) plt.show() .. image:: /auto_examples/images/sphx_glr_example_curvature_directions_001.png :alt: example curvature directions :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.683 seconds) .. _sphx_glr_download_auto_examples_example_curvature_directions.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_curvature_directions.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_curvature_directions.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_