Exemplo n.º 1
0
    def to_world_coords(self, object_in_lcs):
        """Returns the object's coordinates in the global coordinate frame.

        Parameters
        ----------
        object_in_lcs : :class:`compas.geometry.Point` or :class:`compas.geometry.Vector` or :class:`compas.geometry.Frame` or list of float
            An object in local coordinate system of the frame.

        Returns
        -------
        :class:`compas.geometry.Point` or :class:`compas.geometry.Vector` or :class:`compas.geometry.Frame`
            The object in the world coordinate frame.

        Notes
        -----
        If you pass a list of float, it is assumed to represent a point.

        Examples
        --------
        >>> from compas.geometry import Point
        >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
        >>> pl = Point(1.632, -0.090, 0.573) # point in frame
        >>> pw = frame.to_world_coords(pl) # point in wcf
        >>> frame.to_local_coords(pw)
        Point(1.632, -0.090, 0.573)
        """
        T = Transformation.change_basis(self, Frame.worldXY())
        if isinstance(object_in_lcs, list):
            return Point(*object_in_lcs).transformed(T)
        else:
            return object_in_lcs.transformed(T)
Exemplo n.º 2
0
    def local_to_local_coords(frame1, frame2, object_in_frame1):
        """Returns the object's coordinates in frame1 in the local coordinates of frame2.

        Parameters
        ----------
        frame1 : :class:`compas.geometry.Frame`
            A frame representing one local coordinate system.
        frame2 : :class:`compas.geometry.Frame`
            A frame representing another local coordinate system.
        object_in_frame1 : :class:`compas.geometry.Point` or :class:`compas.geometry.Vector` or :class:`compas.geometry.Frame` or list of float
            An object in the coordinate frame1. If you pass a list of float, it is assumed to represent a point.

        Returns
        -------
        :class:`compas.geometry.Point` or :class:`compas.geometry.Vector` or :class:`compas.geometry.Frame`
            The object in the local coordinate system of frame2.

        Examples
        --------
        >>> from compas.geometry import Point
        >>> frame1 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
        >>> frame2 = Frame([2, 1, 3], [1., 0., 0.], [0., 1., 0.])
        >>> p1 = Point(2, 2, 2) # point in frame1
        >>> p2 = Frame.local_to_local_coords(frame1, frame2, p1) # point in frame2
        >>> Frame.local_to_local_coords(frame2, frame1, p2)
        Point(2.000, 2.000, 2.000)
        """
        T = Transformation.change_basis(frame1, frame2)
        if isinstance(object_in_frame1, list):
            return Point(*object_in_frame1).transformed(T)
        else:
            return object_in_frame1.transformed(T)
Exemplo n.º 3
0
def worldxy_to_robot_base_xform(robot_base_frame):
    """Calculate the transformation matrix for transformations between WCS to RCS.

    Parameters
    ----------
    robot_base_frame : :class:`compas.geometry.Frame`
        Robot base frame in WCS. The frame origin is the location of the RCS origo
        in WCS, the X axis and Y axis are the X and Y axes of the RCS in WCS.

    Returns
    -------
    :class:`compas.geometry.Transformation`
        The transformation matrix.
    """
    return Transformation.change_basis(Frame.worldXY(), robot_base_frame)
"""Change-basis transformation vs transformation between two frames.
"""
from compas.geometry import Point
from compas.geometry import Frame
from compas.geometry import Transformation

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])

# transformation between 2 frames F1, F2
Tf = Transformation.from_frame_to_frame(F1, F2)
# change-basis transformation between two frames F1 and F2.
Tc = Transformation.change_basis(F1, F2)

# they are different
print(Tf)
print(Tc)

# This is how to use Tf: transform geometry into another coordinate frame
pt = Point(2, 2, 2)
pt.transform(Tf)
print(pt, "==", F2.point)

# This is how to use Tc: represent geometry in another coordinate frame
pt = Point(0, 0, 0)  # local point in F1
pt.transform(Tc)
print(pt, "==", F2.to_local_coords(F1.point))