def normals(vertices, indices):
 (vertices, indices, mapping) = compact(vertices, indices)
 T = vertices[indices]
 N = np.cross((T[:, 1] - T[:, 0]), (T[:, 2] - T[:, 0]))
 L = np.sqrt(np.sum((N * N), axis=1))
 L[(L == 0)] = 1.0
 N /= L[:, np.newaxis]
 normals = np.zeros_like(vertices)
 normals[indices[:, 0]] += N
 normals[indices[:, 1]] += N
 normals[indices[:, 2]] += N
 L = np.sqrt(np.sum((normals * normals), axis=1))
 L[(L == 0)] = 1.0
 normals /= L[:, np.newaxis]
 return normals[mapping]

def normals ( vertices , indices ) : ( vertices , indices , mapping ) = compact ( vertices , indices ) T = vertices [ indices ] N = np . cross ( ( T [ : , 1 ] - T [ : , 0 ] ) , ( T [ : , 2 ] - T [ : , 0 ] ) ) L = np . sqrt ( np . sum ( ( N * N ) , axis = 1 ) ) L [ ( L == 0 ) ] = 1.0 N /= L [ : , np . newaxis ] normals = np . zeros_like ( vertices ) normals [ indices [ : , 0 ] ] += N normals [ indices [ : , 1 ] ] += N normals [ indices [ : , 2 ] ] += N L = np . sqrt ( np . sum ( ( normals * normals ) , axis = 1 ) ) L [ ( L == 0 ) ] = 1.0 normals /= L [ : , np . newaxis ] return normals [ mapping ]
compute normals over a triangulated surface parameters vertices : ndarray triangles vertices indices : ndarray triangles indices .