.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_generate_parametric_surfaces.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_generate_parametric_surfaces.py: .. _example_generation_parametric_surfaces: =================================== Generating parametric surfaces in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-16 .. code-block:: Python # Authors: # Guillaume Auzias # Julien Barrès # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 17-21 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 23-24 Importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python import slam.generate_parametric_surfaces as sgps import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 28-29 Generating a quadrix surface .. GENERATED FROM PYTHON SOURCE LINES 29-43 .. code-block:: Python K = [1, 1] quadric = sgps.generate_quadric( K, nstep=[20, 20], ax=3, ay=1, random_sampling=True, ratio=0.3, random_distribution_type="gamma", ) quadric_mean_curv = sgps.quadric_curv_mean(K)( np.array(quadric.vertices[:, 0]), np.array(quadric.vertices[:, 1]) ) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Generating an ellipsiods .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python nstep = 50 randomSampling = True a = 2 b = 1 ellips = sgps.generate_ellipsiod(a, b, nstep, randomSampling) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Generating a sphere .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python sphere_regular = sgps.generate_sphere_icosahedron(subdivisions=3, radius=4) .. GENERATED FROM PYTHON SOURCE LINES 56-58 Generating a more randomized sphere (random sampling with the same number of vertices) .. GENERATED FROM PYTHON SOURCE LINES 58-62 .. code-block:: Python sphere_random = sgps.generate_sphere_random_sampling( vertex_number=sphere_regular.vertices.shape[0], radius=4 ) .. GENERATED FROM PYTHON SOURCE LINES 63-64 Computation of the volume and volume error of the spheres .. GENERATED FROM PYTHON SOURCE LINES 64-76 .. code-block:: Python analytical_vol = (4 / 3) * np.pi * np.power(4, 3) print( "volume error for regular sampling: {:.3f}".format( sphere_regular.volume - analytical_vol ) ) print( "volume error for random sampling: {:.3f}".format( sphere_random.volume - analytical_vol ) ) .. rst-class:: sphx-glr-script-out .. code-block:: none volume error for regular sampling: -2.307 volume error for random sampling: -4.951 .. GENERATED FROM PYTHON SOURCE LINES 77-96 VISUALIZATION USING EXTERNAL TOOLS ############################################################################ # import visbrain # visu using visbrain # show the quadric with its mean curvature visb_sc = splt.visbrain_plot( mesh=quadric, tex=quadric_mean_curv, caption="quadric", cblabel="mean curvature" ) # show the ellipsoid visb_sc = splt.visbrain_plot(mesh=ellips, caption="ellipsoid") # show the sphere with regular sampling visb_sc = splt.visbrain_plot(mesh=sphere_regular, caption="sphere_regular") # show the sphere with random sampling visb_sc = splt.visbrain_plot( mesh=sphere_random, caption="sphere_random", visb_sc=visb_sc ) visb_sc.preview() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.074 seconds) .. _sphx_glr_download_auto_examples_example_generate_parametric_surfaces.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_generate_parametric_surfaces.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_generate_parametric_surfaces.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_generate_parametric_surfaces.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_