pysdic.triangle_3_compute_elements_normals#

triangle_3_compute_elements_normals(vertices_coordinates, connectivity)[source]#

Compute the normal vectors of triangular elements defined by the given vertices and connectivity.

The normal vector of each triangular element is computed using the cross product of two edges of the triangle and is normalized to have unit length.

\[\vec{n} = \frac{\vec{AB} \times \vec{AC}}{\| \vec{AB} \times \vec{AC} \|}\]

Note

The input vertices_coordinates will be converted to numpy.float64 for computation. The input connectivity will be converted to numpy.int64 for computation.

Warning

No tests are performed to check if the inputs array content are consistent (e.g., if the connectivity contains invalid vertex indices, …). Only the shapes and types of the input arrays are validated. The behavior of the function is undefined if the input arrays are not consistent.

Parameters:
  • vertices_coordinates (ArrayLike) – An array of shape \((N_v, 3)\) representing the coordinates of the vertices.

  • connectivity (ArrayLike) – An array of shape \((N_e, 3)\) representing the connectivity of the triangular elements.

Returns:

An array of shape \((N_e, 3)\) representing the normal vector of each triangular element.

Return type:

numpy.ndarray

Raises:
  • TypeError – If the inputs are not numpy arrays.

  • ValueError – If the input arrays do not have the correct shapes.

See also

pysdic.triangle_3_compute_elements_areas

For computing the areas of triangular elements.

pysdic.triangle_3_compute_vertices_normals

For computing the normal vectors at each vertex of the mesh.

Examples

Computing the normal vectors of triangular elements:

 1import numpy as np
 2from pysdic import triangle_3_compute_elements_normals
 3
 4vertices = np.array([[0, 0, 0],
 5                     [1, 0, 0],
 6                     [0, 1, 0],
 7                     [0, 0, 1]])  # shape (4, 3)
 8
 9connectivity = np.array([[0, 1, 2],
10                         [0, 1, 3],
11                         [0, 2, 3],
12                         [1, 2, 3]])  # shape (4, 3)
13
14normals = triangle_3_compute_elements_normals(vertices, connectivity)
15print(normals)
[[ 0.  0.  1.]
 [ 0. -1.  0.]
 [ 1.  0.  0.]
 [ 0.57735027  0.57735027  0.57735027]]