mesh.Mesh.normals#

Mesh.normals(location='elems', length=1.0, return_mesh=True)#

Compute normal vectors for a triangular surface mesh.

This function calculates normals either per element (face normals) or per node (averaged nodal normals). The vectors are scaled to the given length and can be returned as a line2 Mesh (useful for visualization), or as a NumPy array.

Parameters#

location{‘elems’, ‘nodes’}, optional
  • ‘elems’ : return one normal per triangle (default).

  • ‘nodes’ : return averaged nodal or vertex normals.

lengthfloat, optional

Desired magnitude of the returned normal vectors. By default normals are scaled to unit length.

return_meshbool, optional

If True (default), returns a line2 Mesh object, where each line segment runs from its anchor point to its endpoint. If False the function returns a NumPy array of shape (N, 3), where N is the number of normals.

Returns#

Mesh or ndarray
  • If return_mesh=True: a new line2 Mesh representing the normals.

  • If return_mesh=False: a (N,3) array of normal vectors.

Notes#

  • Implemented only for meshes with eltype='tri3'.

  • Element normals are outward according to the element orientation.

Examples#

>>> mesh = shapes.cuboid()
>>> print(mesh.normals())
Mesh: n_nodes: 24, n_elems: 12, plexitude: 2, level: 1, eltype: line2
  BBox: [-1. -1. -1.], [2. 2. 2.]
  Size: [3. 3. 3.]
  Length: 12.0
>>> node_normals = mesh.normals(location='nodes', length=2.0)
>>> np.isclose(np.linalg.norm(node_normals[0]), 2.0)
True