
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/02_stack_mesh_mixin/p02_surface.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_02_stack_mesh_mixin_p02_surface.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_02_stack_mesh_mixin_p02_surface.py:


Reconstructing Surfaces
=======================

This example demonstrates :meth:`~pyvisual.core.mixins.StackMeshMixin.add_surface`
— the method for building a triangulated surface through scattered spherical
coordinate points using one of three reconstruction strategies:
``'delaunay_2d'``, ``'delaunay_3d'``, or ``'reconstruct_surface'``.

.. GENERATED FROM PYTHON SOURCE LINES 10-14

.. code-block:: Python


    import numpy as np
    from pyvisual import Plot3d








.. GENERATED FROM PYTHON SOURCE LINES 15-26

Surface of Revolution
---------------------

The surface below is defined by the relation :math:`r = 5\sin\theta`, sampled
at 10 equally-spaced longitudes and 100 latitudinal points per meridian.
The resulting point cloud forms a closed, non-planar surface that wraps
around itself — the default ``'delaunay_2d'`` projects points onto a plane
before triangulating, which produces incorrect connectivity for such a surface.
:meth:`~pyvista.DataSetFilters.delaunay_3d` instead builds a full volumetric
tetrahedralization and extracts the outer boundary, correctly handling the
closed topology.  The surface is colored by colatitude :math:`\theta`.

.. GENERATED FROM PYTHON SOURCE LINES 26-38

.. code-block:: Python


    n_lines, n_pts = 10, 100
    t = np.tile(np.linspace(0, np.pi, n_pts), (n_lines, 1))
    r = 5 * np.sin(t)
    p = np.tile(np.linspace(0, 2 * np.pi, n_lines)[:, None], (1, n_pts))

    plotter = Plot3d()
    plotter.show_axes()
    plotter.add_sun()
    plotter.add_surface(r, t, p, t, method='delaunay_3d')
    plotter.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /gallery/02_stack_mesh_mixin/images/sphx_glr_p02_surface_001.png
        :alt: p02 surface
        :srcset: /gallery/02_stack_mesh_mixin/images/sphx_glr_p02_surface_001.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /Users/rdavidson/MHDweb/pyvisual/docs/source/gallery/02_stack_mesh_mixin/images/sphx_glr_p02_surface_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 39-46

Open Shell Patch (``delaunay_2d``)
----------------------------------

For nearly-planar or open surfaces, ``'delaunay_2d'`` gives better results.
The example below samples a spherical cap at :math:`r = 3\,R_\odot` over a
limited colatitude/longitude range and reconstructs it as a surface patch
colored by longitude :math:`\phi`.

.. GENERATED FROM PYTHON SOURCE LINES 46-58

.. code-block:: Python


    n_t, n_p = 20, 40
    t_vals = np.tile(np.linspace(np.pi / 6, np.pi / 3, n_t), (n_p, 1)).T
    p_vals = np.tile(np.linspace(0, np.pi / 2, n_p), (n_t, 1))
    r_vals = np.full_like(t_vals, 3.0)

    plotter = Plot3d()
    plotter.show_axes()
    plotter.add_sun()
    plotter.add_surface(r_vals, t_vals, p_vals, p_vals, method='delaunay_2d',
                        show_scalar_bar=False)
    plotter.show()







.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /gallery/02_stack_mesh_mixin/images/sphx_glr_p02_surface_002.png
        :alt: p02 surface
        :srcset: /gallery/02_stack_mesh_mixin/images/sphx_glr_p02_surface_002.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /Users/rdavidson/MHDweb/pyvisual/docs/source/gallery/02_stack_mesh_mixin/images/sphx_glr_p02_surface_002.vtksz







.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.088 seconds)


.. _sphx_glr_download_gallery_02_stack_mesh_mixin_p02_surface.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: p02_surface.ipynb <p02_surface.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: p02_surface.py <p02_surface.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: p02_surface.zip <p02_surface.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
