From 8cbe2980728644cbe22667e44ae88e2a592882c7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 18 Jul 2023 14:28:18 +1000 Subject: [PATCH] Utility function to create rotation matrixes in numpy. --- .../ifcopenshell/util/placement.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/placement.py b/src/ifcopenshell-python/ifcopenshell/util/placement.py index fe6e8f78bb..7219cd6856 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/placement.py +++ b/src/ifcopenshell-python/ifcopenshell/util/placement.py @@ -101,3 +101,30 @@ def get_storey_elevation(storey): matrix = get_local_placement(storey.ObjectPlacement) return matrix[2][3] return getattr(storey, "Elevation", 0.0) or 0.0 + + +def rotation(angle, axis, is_degrees=True): + theta = np.radians(angle) if is_degrees else angle + cos, sin = np.cos(theta), np.sin(theta) + + if axis == "X": + return np.array([ + [1, 0, 0, 0], + [0, cos, -sin, 0], + [0, sin, cos, 0], + [0, 0, 0, 1] + ]) + elif axis == "Y": + return np.array([ + [cos, 0, sin, 0], + [0, 1, 0, 0], + [-sin, 0, cos, 0], + [0, 0, 0, 1] + ]) + elif axis == "Z": + return np.array([ + [cos, -sin, 0, 0], + [sin, cos, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1] + ])