MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / get_area_vf

Function get_area_vf

src/ifcopenshell-python/ifcopenshell/util/shape.py:440–458  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

438
439
440def 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
461def get_area(geometry: W.Triangulation) -> float:

Callers 3

get_areaFunction · 0.85
get_side_areaFunction · 0.85
get_outer_surface_areaFunction · 0.85

Calls 2

normMethod · 0.80
itemMethod · 0.80

Tested by

no test coverage detected