def represent_vector_in_local_coordinates(self, vector): """Represents a vector in the frame's local coordinate system. Parameters ---------- vector : :obj:`list` of :obj:`float` or :class:`Vector` A vector in world XY. Returns ------- :class:`Vector` A vector in the local coordinate system of the frame. Examples -------- >>> from compas.geometry import Frame >>> f = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> pw1 = [2, 2, 2] >>> pf = f.represent_vector_in_local_coordinates(pw1) >>> pw2 = f.represent_vector_in_global_coordinates(pf) >>> allclose(pw1, pw2) True """ T = inverse(matrix_from_basis_vectors(self.xaxis, self.yaxis)) vec = Vector(*vector) vec.transform(T) return vec
def represent_point_in_local_coordinates(self, point): """Represents a point in the frame's local coordinate system. Parameters ---------- point : :obj:`list` of :obj:`float` or :class:`Point` A point in world XY. Returns ------- :class:`Point` A point in the local coordinate system of the frame. Examples -------- >>> from compas.geometry import Frame >>> f = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> pw1 = [2, 2, 2] >>> pf = f.represent_point_in_local_coordinates(pw1) >>> pw2 = f.represent_point_in_global_coordinates(pf) >>> allclose(pw1, pw2) True """ pt = Point(*subtract_vectors(point, self.point)) T = inverse(matrix_from_basis_vectors(self.xaxis, self.yaxis)) pt.transform(T) return pt
def from_frame_to_frame(cls, frame_from, frame_to): """Computes a change of basis transformation between two frames. This transformation maps geometry from one Cartesian coordinate system defined by "frame_from" to the other Cartesian coordinate system defined by "frame_to". Args: frame_from (:class:`Frame`): a frame defining the original Cartesian coordinate system frame_to (:class:`Frame`): a frame defining the targeted Cartesian coordinate system Example: >>> 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, inverse(T1.matrix)))
def inverse(self): """Returns the inverse transformation. Example: >>> from compas.geometry import Frame >>> f = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> T = Transformation.from_frame(f) >>> I = Transformation() # identity matrix >>> I == T * T.inverse() True """ cls = type(self) return cls(inverse(self.matrix))