mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
More efficient shape bbox and average vertex centroid function
This commit is contained in:
@@ -175,18 +175,21 @@ def get_bbox_centroid(geometry: ShapeType) -> tuple[float, float, float]:
|
|||||||
:return: A tuple representing the XYZ centroid
|
:return: A tuple representing the XYZ centroid
|
||||||
:rtype: tuple[float, float, float]
|
:rtype: tuple[float, float, float]
|
||||||
"""
|
"""
|
||||||
verts_flat = get_vertices(geometry).ravel()
|
vertices_array = np.array(geometry.verts).reshape(-1, 3)
|
||||||
x_values = verts_flat[0::3]
|
return (np.min(vertices_array, axis=0) + np.max(vertices_array, axis=0)) / 2
|
||||||
y_values = verts_flat[1::3]
|
|
||||||
z_values = verts_flat[2::3]
|
|
||||||
minx = min(x_values)
|
def get_vert_centroid(geometry: ShapeType) -> tuple[float, float, float]:
|
||||||
maxx = max(x_values)
|
"""Calculates the average vertex centroid of the geometry
|
||||||
miny = min(y_values)
|
|
||||||
maxy = max(y_values)
|
The centroid is in local coordinates relative to the object's placement.
|
||||||
minz = min(z_values)
|
|
||||||
maxz = max(z_values)
|
:param geometry: Geometry output calculated by IfcOpenShell
|
||||||
res = np.array((minx + ((maxx - minx) / 2), miny + ((maxy - miny) / 2), minz + ((maxz - minz) / 2)))
|
:type geometry: geometry
|
||||||
return res.tolist()
|
:return: A tuple representing the XYZ centroid
|
||||||
|
:rtype: tuple[float, float, float]
|
||||||
|
"""
|
||||||
|
return np.mean(np.array(geometry.verts).reshape(-1, 3), axis=0)
|
||||||
|
|
||||||
|
|
||||||
def get_element_bbox_centroid(element: ifcopenshell.entity_instance, geometry) -> npt.NDArray[np.float64]:
|
def get_element_bbox_centroid(element: ifcopenshell.entity_instance, geometry) -> npt.NDArray[np.float64]:
|
||||||
|
|||||||
Reference in New Issue
Block a user