Main Content

computeNormals

Compute unit normals for mesh vertices and faces

Since R2022b

    Description

    computeNormals(mesh) computes the unit normal vector for the vertices and the faces of the surface mesh mesh. The function overwrites the existing vertex and face normal vectors.

    example

    computeNormals(mesh,"vertices") computes the unit normal vector for only the mesh vertices. A vertex normal is the average of the face normal vectors of all the faces that share the vertex. The function uses the existing face normal vectors to compute the vertex normal vectors.

    computeNormals(mesh,"faces") computes the unit normal vectors for only the mesh faces.

    Examples

    collapse all

    Define mesh vertices for a surface mesh.

    vertices = [1 -1  1; 1 1 1; -1 1 1; -1 -1 1; ...
                1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 -1];

    Define the mesh faces using the vertices.

    faces = [6 2 1; 1 5 6; 8 4 3; 3 7 8; 6 7 3; 3 2 6; ...
             5 1 4; 4 8 5; 4 1 2; 2 3 4; 7 6 5; 5 8 7];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);

    Compute the unit normal vectors for the mesh vertices and faces.

    computeNormals(mesh);
    mesh
    mesh = 
      surfaceMesh with properties:
    
             Vertices: [8x3 double]
                Faces: [12x3 int32]
        VertexNormals: [8x3 double]
         VertexColors: []
          FaceNormals: [12x3 double]
           FaceColors: []
          NumVertices: 8
             NumFaces: 12
    
    

    Input Arguments

    collapse all

    Surface mesh, specified as a surfaceMesh object.

    Version History

    Introduced in R2022b