def test_matrix_inverse(R, T): assert matrix_inverse( R.matrix) == [[1.0, -0.0, 0.0, -0.0], [-0.0, -0.4480736161291701, 0.8939966636005579, 0.0], [0.0, -0.8939966636005579, -0.4480736161291701, -0.0], [-0.0, 0.0, -0.0, 1.0]] assert matrix_inverse(T.matrix) == [[1.0, -0.0, 0.0, -1.0], [-0.0, 1.0, -0.0, -2.0], [0.0, -0.0, 1.0, -3.0], [-0.0, 0.0, -0.0, 1.0]]
def from_change_of_basis(cls, frame_from, frame_to): """Computes a change of basis transformation between two frames. A basis change is essentially a remapping of geometry from one coordinate system to another. Parameters ---------- frame_from : :class:`Frame` A frame defining the original Cartesian coordinate system. frame_to : :class:`Frame` A frame defining the targeted Cartesian coordinate system. Examples -------- >>> from compas.geometry import Point, Frame >>> f1 = Frame([2, 2, 2], [0.12, 0.58, 0.81], [-0.80, 0.53, -0.26]) >>> f2 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> T = Transformation.from_change_of_basis(f1, f2) >>> p_f1 = Point(1, 1, 1) # point in f1 >>> p_f1.transformed(T) # point represented in f2 Point(1.395, 0.955, 1.934) >>> Frame.local_to_local_coordinates(f1, f2, p_f1) Point(1.395, 0.955, 1.934) """ T1 = cls.from_frame(frame_from) T2 = cls.from_frame(frame_to) return cls(multiply_matrices(matrix_inverse(T2.matrix), T1.matrix))
def from_frame_to_frame(cls, frame_from, frame_to): """Computes a transformation between two frames. This transformation allows to transform geometry from one Cartesian coordinate system defined by "frame_from" to another Cartesian coordinate system defined by "frame_to". Parameters ---------- frame_from : :class:`Frame` A frame defining the original Cartesian coordinate system. frame_to : :class:`Frame` A frame defining the targeted Cartesian coordinate system. Returns ------- Transformation The ``Transformation`` object representing a change of basis. Examples -------- >>> from compas.geometry import Frame >>> f1 = Frame([2, 2, 2], [0.12, 0.58, 0.81], [-0.80, 0.53, -0.26]) >>> f2 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> T = Transformation.from_frame_to_frame(f1, f2) >>> f1.transform(T) >>> f1 == f2 True """ T1 = cls.from_frame(frame_from) T2 = cls.from_frame(frame_to) return cls(multiply_matrices(T2.matrix, matrix_inverse(T1.matrix)))
def from_factors(cls, factors, frame=None): """Construct a scale transformation from scale factors. Parameters ---------- factors : list of float The scale factors along X, Y, Z. frame : :class:`compas.geometry.Frame`, optional The anchor frame for the scaling transformation. Defaults to ``None``. Returns ------- Scale A scale transformation. Examples -------- >>> point = Point(2, 5, 0) >>> frame = Frame(point, (1, 0, 0), (0, 1, 0)) >>> points = [point, Point(2, 10, 0)] >>> S = Scale.from_factors([2.] * 3, frame) >>> [p.transformed(S) for p in points] [Point(2.000, 5.000, 0.000), Point(2.000, 15.000, 0.000)] """ S = cls() if frame: Tw = matrix_from_frame(frame) Tl = matrix_inverse(Tw) Sc = matrix_from_scale_factors(factors) S.matrix = multiply_matrices(multiply_matrices(Tw, Sc), Tl) else: S.matrix = matrix_from_scale_factors(factors) return S
def invert(self): """Invert this transformation. Returns ------- None The transformation is transposed in-place. """ self.matrix = matrix_inverse(self.matrix)
def invert(self): """Invert this transformation.""" self.matrix = matrix_inverse(self.matrix)