Example #1
0
    def transform(self, transformation):
        """Transform the frame.

        Parameters
        ----------
        transformation : :class:`Transformation`
            The transformation used to transform the Frame.

        Examples
        --------
        >>> from compas.geometry import Frame
        >>> from compas.geometry import Transformation
        >>> f1 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
        >>> T = Transformation.from_frame(f1)
        >>> f2 = Frame.worldXY()
        >>> f2.transform(T)
        >>> f1 == f2
        True

        """
        T = transformation * Transformation.from_frame(self)
        point = T.translation
        xaxis, yaxis = T.basis_vectors
        self.point = point
        self.xaxis = xaxis
        self.yaxis = yaxis
Example #2
0
    def represent_frame_in_global_coordinates(self, frame):
        """Represents another frame in the local coordinate system in the world
            coordinate system.

        Parameters
        ----------
        frame: :class:`Frame`
            A frame in the local coordinate system.

        Returns
        -------
        :class:`Frame`
            A frame in the world coordinate system.

        Examples
        --------
        >>> from compas.geometry import Frame
        >>> f = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
        >>> pw1 = Frame([1, 1, 1], [0.707, 0.707, 0], [-0.707, 0.707, 0])
        >>> pf = f.represent_frame_in_local_coordinates(pw1)
        >>> pw2 = f.represent_frame_in_global_coordinates(pf)
        >>> allclose(pw1.point, pw2.point)
        True
        >>> allclose(pw1.xaxis, pw2.xaxis)
        True
        >>> allclose(pw1.yaxis, pw2.yaxis)
        True

        """
        T = Transformation.from_frame(self)
        f = frame.copy()
        f.transform(T)
        return f
Example #3
0
 def get_tool0_transformation(self, T5):
     """Get the transformation to reach tool0_frame.
     """
     return T5 * Transformation.from_frame(self.tool0_frame)
Example #4
0
 def get_tcp_frame_from_tool0_frame(self, frame_tool0):
     """Get the tcp frame from the tool0 frame.
     """
     T = Transformation.from_frame(frame_tool0)
     return Frame.from_transformation(T * self.transformation_tcp_tool0)
Example #5
0
 def get_tool0_frame_from_tcp_frame(self, frame_tcp):
     """Get the tool0 frame (frame at robot) from the tool frame (frame_tcp).
     """
     T = Transformation.from_frame(frame_tcp)
     return Frame.from_transformation(T * self.transformation_tool0_tcp)
Example #6
0
 def init_transformation(self):
     if self.init_origin:
         return Transformation.from_frame(self.init_origin)
     else:
         return Transformation()
Example #7
0
 def current_transformation(self):
     if self.origin:
         return Transformation.from_frame(self.origin)
     else:
         return Transformation()
Example #8
0
# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    f1 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    R = Rotation.from_frame(f1)
    f2 = Frame.from_rotation(R, point=f1.point)
    print(f1 == f2)

    print(f2)

    f1 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    T = Transformation.from_frame(f1)
    f2 = Frame.from_transformation(T)
    print(f1 == f2)

    ea1 = [0.5, 0.4, 0.8]
    M = matrix_from_euler_angles(ea1)
    f = Frame.from_matrix(M)
    ea2 = f.euler_angles()
    print(allclose(ea1, ea2))

    q1 = [0.945, -0.021, -0.125, 0.303]
    f = Frame.from_quaternion(q1, point=[1., 1., 1.])
    q2 = f.quaternion
    print(allclose(q1, q2, tol=1e-03))

    aav1 = [-0.043, -0.254, 0.617]