Computing Surface Normals

Compute normals on a surface.

# sphinx_gallery_thumbnail_number = 2
from pyvista import examples

Computing the normals of a surace is quite easy using pyvista.PolyData’s compute_normals method

mesh = examples.download_topo_global()
mesh.plot(cmap="gist_earth", show_scalar_bar=False)
../../_images/sphx_glr_compute-normals_001.png

Now we have a surface dataset of the globe loaded - unfortunately, the dataset shows the globe with a uniform radius which hides topographic relief. Using pyvista.PolyData.compute_normals(), we can compute the normal vectors on the globe at all points in the dataset, then use the values given in the dataset to warp the surface in the normals direction to create some exaggerated topographic relief.

# Compute the normals in-place and use them to warp the globe
mesh.compute_normals(inplace=True)  # this activates the normals as well

# Now use those normals to warp the surface
warp = mesh.warp_by_scalar(factor=0.5e-5)

# And let's see it!
warp.plot(cmap="gist_earth", show_scalar_bar=False)
../../_images/sphx_glr_compute-normals_002.png

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

Gallery generated by Sphinx-Gallery