Skip to content

per_vertex_normals

per_vertex_normals(V, F)

Normal vectors to all vertices on a mesh

Computes area-weighted per-vertex unit normal vectors for a triangle mesh

Parameters:

Name Type Description Default
V (n,d) numpy array

vertex list of a triangle mesh

required
F (m,3) numpy int array

face index list of a triangle mesh

required

Returns:

Name Type Description
N (m,d) numpy double array

Matrix of per-vertex normals

See Also

per_face_normals.

Examples:

TODO

Source code in src/gpytoolbox/per_vertex_normals.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def per_vertex_normals(V,F):
    """Normal vectors to all vertices on a mesh

    Computes area-weighted per-vertex unit normal vectors for a triangle mesh

    Parameters
    ----------
    V : (n,d) numpy array
        vertex list of a triangle mesh
    F : (m,3) numpy int array
        face index list of a triangle mesh

    Returns
    -------
    N : (m,d) numpy double array
        Matrix of per-vertex normals

    See Also
    --------
    per_face_normals.

    Examples
    --------
    TODO
    """

    # First compute face normals
    face_normals = per_face_normals(V,F,unit_norm=True)
    # We blur these normals onto vertices, weighing by area
    areas = doublearea(V,F)
    vals = np.concatenate((areas,areas,areas))
    J = np.linspace(0,F.shape[0]-1,F.shape[0],dtype=int)
    J = np.concatenate((J,J,J))
    I = np.concatenate((F[:,0],F[:,1],F[:,2]))

    weight_mat = csr_matrix((vals,(I,J)),shape=(V.shape[0],F.shape[0]))

    vertex_normals = weight_mat @ face_normals
    # Now, normalize
    N = vertex_normals/np.tile(np.linalg.norm(vertex_normals,axis=1)[:,None],(1,3))

    return N