mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +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 = set(absolute_placements)
|
||||
|
||||
angle = float(self.args[3])
|
||||
transformation = self.z_rotation_matrix(math.radians(angle)) if angle else np.eye(4)
|
||||
transformation = self.identity_matrix()
|
||||
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[1][3] += float(self.args[1])
|
||||
transformation[2][3] += float(self.args[2])
|
||||
@@ -55,13 +62,29 @@ class Patcher:
|
||||
return self.get_absolute_placement(object_placement.PlacementRelTo)
|
||||
return object_placement
|
||||
|
||||
def z_rotation_matrix(self, angle):
|
||||
return [
|
||||
[math.cos(angle), -math.sin(angle), 0., 0.],
|
||||
[math.sin(angle), math.cos(angle), 0., 0.],
|
||||
[0., 0., 1., 0.],
|
||||
[0., 0., 0., 1.],
|
||||
]
|
||||
def identity_matrix(self):
|
||||
return np.eye(4)
|
||||
|
||||
def x_rotation_matrix(self, angle, transformation):
|
||||
transformation[1][1] = math.cos(angle)
|
||||
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):
|
||||
x = np.array((m[0][0], m[1][0], m[2][0]))
|
||||
|
||||
Reference in New Issue
Block a user