pysdic.triangle_3_compute_vertices_normals#

triangle_3_compute_vertices_normals(vertices_coordinates, connectivity)[source]#

Compute the normal vectors at each vertex of a triangular mesh.

The normal vector at each vertex is computed as the average of the normal vectors of the adjacent triangular elements, weighted by the area of each element.

\[\vec{n}_v = \frac{\sum_{e \in \text{adj}(v)} \text{Area}_e \cdot \vec{n}_e}{\| \sum_{e \in \text{adj}(v)} \text{Area}_e \cdot \vec{n}_e \|}\]

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_v, 3)\) representing the normal vectors at each vertex.

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_elements_normals

For computing the normal vectors of triangular elements.

Examples

Computing the normal vectors at each vertex of a triangular mesh:

 1import numpy as np
 2from pysdic import triangle_3_compute_vertices_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
14vertex_normals = triangle_3_compute_vertices_normals(vertices, connectivity)
15print(vertex_normals)
[[ 0.57735027 -0.57735027  0.57735027]
 [ 0.4472136   0.          0.89442719]
 [ 0.66666667  0.33333333  0.66666667]
 [ 0.89442719  0.          0.4472136 ]]