From 74bc452ad97ee45bdce9c3dcab2887faa7ebf4e0 Mon Sep 17 00:00:00 2001 From: Roger Maitland Date: Fri, 3 Mar 2023 16:18:27 -0500 Subject: [PATCH] Refactored Plane.rotated to use quaternions to match other rotates --- src/build123d/geometry.py | 32 +++++++++----------------------- src/build123d/topology.py | 4 ---- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/build123d/geometry.py b/src/build123d/geometry.py index d5b8d1b..2456062 100644 --- a/src/build123d/geometry.py +++ b/src/build123d/geometry.py @@ -1664,7 +1664,7 @@ class Plane: """ self._origin = self.from_local_coords((x, y)) - def rotated(self, rotate: VectorLike = (0, 0, 0)) -> Plane: + def rotated(self, rotation: VectorLike = (0, 0, 0)) -> Plane: """Returns a copy of this plane, rotated about the specified axes Since the z axis is always normal the plane, rotating around Z will @@ -1676,32 +1676,18 @@ class Plane: manually chain together multiple rotate() commands. Args: - rotate (VectorLike, optional): (xDegrees, yDegrees, zDegrees). Defaults to (0, 0, 0). + rotation (VectorLike, optional): (xDegrees, yDegrees, zDegrees). Defaults to (0, 0, 0). Returns: Plane: a copy of this plane rotated as requested. """ - # NB: this is not a geometric Vector - rotate = Vector(rotate) - # Convert to radians. - rotate = rotate.multiply(pi / 180.0) - - # Compute rotation matrix. - transformation1 = gp_Trsf() - transformation1.SetRotation( - gp_Ax1(gp_Pnt(*(0, 0, 0)), gp_Dir(*self.x_dir.to_tuple())), rotate.X - ) - transformation2 = gp_Trsf() - transformation2.SetRotation( - gp_Ax1(gp_Pnt(*(0, 0, 0)), gp_Dir(*self.y_dir.to_tuple())), rotate.Y - ) - transformation3 = gp_Trsf() - transformation3.SetRotation( - gp_Ax1(gp_Pnt(*(0, 0, 0)), gp_Dir(*self.z_dir.to_tuple())), rotate.Z - ) - transformation = Matrix( - gp_GTrsf(transformation1 * transformation2 * transformation3) - ) + # Note: this is not a geometric Vector + rotation = [radians(a) for a in rotation] + quaternion = gp_Quaternion() + quaternion.SetEulerAngles(gp_EulerSequence.gp_Intrinsic_XYZ, *rotation) + trsf_rotation = gp_Trsf() + trsf_rotation.SetRotation(quaternion) + transformation = Matrix(gp_GTrsf(trsf_rotation)) # Compute the new plane. new_xdir = self.x_dir.transform(transformation) diff --git a/src/build123d/topology.py b/src/build123d/topology.py index ed808a3..0941eab 100644 --- a/src/build123d/topology.py +++ b/src/build123d/topology.py @@ -169,15 +169,11 @@ from OCP.gp import ( gp_Dir, gp_Dir2d, gp_Elips, - gp_EulerSequence, - gp_GTrsf, gp_Pln, gp_Pnt, gp_Pnt2d, - gp_Quaternion, gp_Trsf, gp_Vec, - gp_XYZ, ) # properties used to store mass calculation result