diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py index ab7914cfd6..e08af14fd7 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py @@ -19,7 +19,7 @@ import ifcopenshell.util.unit from ifcopenshell.util.shape_builder import ShapeBuilder, V from itertools import chain -from mathutils import Vector +from mathutils import Vector, Matrix import collections import mathutils from pprint import pprint @@ -106,8 +106,11 @@ class Usecase: solid = builder.create_swept_disk_solid(polyline, support_radius) support_disk_circle = builder.circle(radius=support_disk_radius) + + angle = V(0, 1).angle_signed(ortho_dir.xy) + y_extrusion_kwargs = builder.rotate_extrusion_kwargs_by_z(builder.extrude_by_y_kwargs(), angle) support_disk = builder.extrude( - support_disk_circle, support_disk_depth, position=support_points[-1], **builder.extrude_by_y_kwargs() + support_disk_circle, support_disk_depth, position=support_points[-1], **y_extrusion_kwargs ) return [solid, support_disk] diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py index b2e814278b..87d91e9274 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py @@ -568,3 +568,18 @@ class ShapeBuilder: "position_z_axis": Vector((0, -1, 0)), "extrusion_vector": Vector((0, 0, -1)), } + + def rotate_extrusion_kwargs_by_z(self, kwargs, angle, counter_clockwise=False): + """shortcut to rotate extrusion kwargs by z axis + + `kwargs` expected to have `position_x_axis` and `position_z_axis` keys + + `angle` is a rotation value in radians + + by default rotation is clockwise, to make it counter clockwise use `counter_clockwise` flag + """ + rot = Matrix.Rotation(-angle, 3, "Z") + kwargs = kwargs.copy() # prevent mutation of original kwargs + kwargs["position_x_axis"].rotate(rot) + kwargs["position_z_axis"].rotate(rot) + return kwargs