def triangulate_face(data): """Determines the triangulation of the face of a shape. Parameters ---------- data : np.ndarray Nx2 array of vertices of shape to be triangulated Returns ------- vertices : np.ndarray Mx2 array vertices of the triangles. triangles : np.ndarray Px3 array of the indices of the vertices that will form the triangles of the triangulation """ if triangulate is not None: len_data = len(data) edges = np.empty((len_data, 2), dtype=np.uint32) edges[:, 0] = np.arange(len_data) edges[:, 1] = np.arange(1, len_data + 1) # connect last with first vertex edges[-1, 1] = 0 res = triangulate(dict(vertices=data, segments=edges), "p") vertices, triangles = res['vertices'], res['triangles'] else: vertices, triangles = PolygonData(vertices=data).triangulate() triangles = triangles.astype(np.uint32) return vertices, triangles
def triangulate_face(data): """Determines the triangulation of the face of a shape. Parameters ---------- data : np.ndarray Nx2 array of vertices of shape to be triangulated Returns ------- vertices : np.ndarray Mx2 array vertices of the trinagles. triangles : np.ndarray Px3 array of the indices of the vertices that will form the triangles of the triangulation """ vertices, triangles = PolygonData(vertices=data).triangulate() triangles = triangles.astype(np.uint32) return vertices, triangles