Calculates the surface area given a list of vertices and triangulated faces :param vertices: A list of 3D vertices, such as returned from get_vertices. :param faces: A list of faces, such as returned from get_faces. :return: The surface area.
(vertices: npt.NDArray[np.float64], faces: npt.NDArray[np.int32])
| 438 | |
| 439 | |
| 440 | def get_area_vf(vertices: npt.NDArray[np.float64], faces: npt.NDArray[np.int32]) -> float: |
| 441 | """Calculates the surface area given a list of vertices and triangulated faces |
| 442 | |
| 443 | :param vertices: A list of 3D vertices, such as returned from get_vertices. |
| 444 | :param faces: A list of faces, such as returned from get_faces. |
| 445 | :return: The surface area. |
| 446 | """ |
| 447 | # Calculate the triangle normal vectors |
| 448 | v1 = vertices[faces[:, 1]] - vertices[faces[:, 0]] |
| 449 | v2 = vertices[faces[:, 2]] - vertices[faces[:, 0]] |
| 450 | triangle_normals = np.cross(v1, v2) |
| 451 | |
| 452 | # Normalize the normal vectors to get their length (i.e., triangle area) |
| 453 | triangle_areas = np.linalg.norm(triangle_normals, axis=1) / 2 |
| 454 | |
| 455 | # Sum up the areas to get the total area of the mesh |
| 456 | mesh_area = np.sum(triangle_areas) |
| 457 | |
| 458 | return mesh_area.item() |
| 459 | |
| 460 | |
| 461 | def get_area(geometry: W.Triangulation) -> float: |
no test coverage detected