compute_normals

PolyDataFilters.compute_normals(cell_normals=True, point_normals=True, split_vertices=False, flip_normals=False, consistent_normals=True, auto_orient_normals=False, non_manifold_traversal=True, feature_angle=30.0, inplace=False, progress_bar=False)

Compute point and/or cell normals for a mesh.

The filter can reorder polygons to insure consistent orientation across polygon neighbors. Sharp edges can be split and points duplicated with separate normals to give crisp (rendered) surface definition. It is also possible to globally flip the normal orientation.

The algorithm works by determining normals for each polygon and then averaging them at shared points. When sharp edges are present, the edges are split and new points generated to prevent blurry edges (due to Gouraud shading).

Parameters
cell_normalsbool, optional

Calculation of cell normals. Defaults to True.

point_normalsbool, optional

Calculation of point normals. Defaults to True.

split_verticesbool, optional

Splitting of sharp edges. Defaults to False.

flip_normalsbool, optional

Set global flipping of normal orientation. Flipping modifies both the normal direction and the order of a cell’s points. Defaults to False.

consistent_normalsbool, optional

Enforcement of consistent polygon ordering. Defaults to True.

auto_orient_normalsbool, optional

Turn on/off the automatic determination of correct normal orientation. NOTE: This assumes a completely closed surface (i.e. no boundary edges) and no non-manifold edges. If these constraints do not hold, all bets are off. This option adds some computational complexity, and is useful if you do not want to have to inspect the rendered image to determine whether to turn on the flip_normals flag. However, this flag can work with the flip_normals flag, and if both are set, all the normals in the output will point “inward”. Defaults to False.

non_manifold_traversalbool, optional

Turn on/off traversal across non-manifold edges. Changing this may prevent problems where the consistency of polygonal ordering is corrupted due to topological loops. Defaults to True.

feature_anglefloat, optional

The angle that defines a sharp edge. If the difference in angle across neighboring polygons is greater than this value, the shared edge is considered “sharp”. Defaults to 30.0.

inplacebool, optional

Updates mesh in-place. Defaults to False.

progress_barbool, optional

Display a progress bar to indicate progress.

Returns
pyvista.PolyData

Updated mesh with cell and point normals.

Notes

Previous arrays named "Normals" will be overwritten.

Normals are computed only for polygons and triangle strips. Normals are not computed for lines or vertices.

Triangle strips are broken up into triangle polygons. You may want to restrip the triangles.

It may be easier to run pyvista.PolyData.point_normals() or pyvista.PolyData.cell_normals() if you would just like the array of point or cell normals.

Examples

Compute the point normals of the surface of a sphere.

>>> import pyvista as pv
>>> sphere = pv.Sphere()
>>> sphere = sphere.compute_normals(cell_normals=False)
>>> normals = sphere['Normals']
>>> normals.shape
(842, 3)

Alternatively, create a new mesh when computing the normals and compute both cell and point normals.

>>> import pyvista as pv
>>> sphere = pv.Sphere()
>>> sphere_with_norm = sphere.compute_normals()
>>> sphere_with_norm.point_data['Normals'].shape
(842, 3)
>>> sphere_with_norm.cell_data['Normals'].shape
(1680, 3)

See Computing Surface Normals for more examples using this filter.