mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 12:07:59 +00:00
OffsetObjectPlacements patch now allows 3D rotations, such as to fix wrong Z axis coming from software like Solidworks
This commit is contained in:
@@ -39,8 +39,15 @@ class Patcher:
|
|||||||
absolute_placements.append(absolute_placement)
|
absolute_placements.append(absolute_placement)
|
||||||
absolute_placements = set(absolute_placements)
|
absolute_placements = set(absolute_placements)
|
||||||
|
|
||||||
angle = float(self.args[3])
|
transformation = self.identity_matrix()
|
||||||
transformation = self.z_rotation_matrix(math.radians(angle)) if angle else np.eye(4)
|
if len(self.args) == 4:
|
||||||
|
angle = self.args[3]
|
||||||
|
if angle:
|
||||||
|
transformation = self.z_rotation_matrix(math.radians(angle), transformation)
|
||||||
|
elif len(self.args) == 6:
|
||||||
|
for arg in (("x", self.args[3]), ("y", self.args[4]), ("z", self.args[5])):
|
||||||
|
if arg[1]:
|
||||||
|
transformation = getattr(self, f"{arg[0]}_rotation_matrix")(math.radians(arg[1]), transformation)
|
||||||
transformation[0][3] += float(self.args[0])
|
transformation[0][3] += float(self.args[0])
|
||||||
transformation[1][3] += float(self.args[1])
|
transformation[1][3] += float(self.args[1])
|
||||||
transformation[2][3] += float(self.args[2])
|
transformation[2][3] += float(self.args[2])
|
||||||
@@ -55,13 +62,29 @@ class Patcher:
|
|||||||
return self.get_absolute_placement(object_placement.PlacementRelTo)
|
return self.get_absolute_placement(object_placement.PlacementRelTo)
|
||||||
return object_placement
|
return object_placement
|
||||||
|
|
||||||
def z_rotation_matrix(self, angle):
|
def identity_matrix(self):
|
||||||
return [
|
return np.eye(4)
|
||||||
[math.cos(angle), -math.sin(angle), 0., 0.],
|
|
||||||
[math.sin(angle), math.cos(angle), 0., 0.],
|
def x_rotation_matrix(self, angle, transformation):
|
||||||
[0., 0., 1., 0.],
|
transformation[1][1] = math.cos(angle)
|
||||||
[0., 0., 0., 1.],
|
transformation[1][2] = -math.sin(angle)
|
||||||
]
|
transformation[2][1] = math.sin(angle)
|
||||||
|
transformation[2][2] = math.cos(angle)
|
||||||
|
return transformation
|
||||||
|
|
||||||
|
def y_rotation_matrix(self, angle, transformation):
|
||||||
|
transformation[0][0] = math.cos(angle)
|
||||||
|
transformation[0][2] = math.sin(angle)
|
||||||
|
transformation[2][0] = -math.sin(angle)
|
||||||
|
transformation[2][2] = math.cos(angle)
|
||||||
|
return transformation
|
||||||
|
|
||||||
|
def z_rotation_matrix(self, angle, transformation):
|
||||||
|
transformation[0][0] = math.cos(angle)
|
||||||
|
transformation[0][1] = -math.sin(angle)
|
||||||
|
transformation[1][0] = math.sin(angle)
|
||||||
|
transformation[1][1] = math.cos(angle)
|
||||||
|
return transformation
|
||||||
|
|
||||||
def get_relative_placement(self, m):
|
def get_relative_placement(self, m):
|
||||||
x = np.array((m[0][0], m[1][0], m[2][0]))
|
x = np.array((m[0][0], m[1][0], m[2][0]))
|
||||||
|
|||||||
Reference in New Issue
Block a user