Block.face_matrix
- Block.face_matrix(rtype='array')
Compute the face matrix of the mesh.
- Parameters:
- rtypeLiteral[‘array’, ‘csc’, ‘csr’, ‘coo’, ‘list’], optional
Format of the result.
- Returns:
- array-like
The face matrix.
Notes
The face matrix represents the relationship between faces and vertices. Each row of the matrix represents a face. Each column represents a vertex. The matrix is filled with zeros except where a relationship between a vertex and a face exist.
\[\begin{split}F_{ij} = \begin{cases} 1 & \text{if vertex j is part of face i} \\ 0 & \text{otherwise} \end{cases}\end{split}\]The face matrix can for example be used to compute the centroids of all faces of a mesh.
Examples
>>> from compas.datastructures import Mesh >>> mesh = Mesh.from_polyhedron(6) >>> F = mesh.face_matrix() >>> type(F) <class 'numpy.ndarray'>
>>> from numpy import allclose, asarray >>> xyz = asarray(mesh.vertices_attributes('xyz')) >>> F = mesh.face_matrix(rtype='csr') >>> c1 = F.dot(xyz) / F.sum(axis=1) >>> c2 = [mesh.face_centroid(fkey) for fkey in mesh.faces()] >>> allclose(c1, c2) True