Exemple #1
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:`Frame`
            A frame representing one local coordinate system.
        frame2 : :class:`Frame`
            A frame representing another local coordinate system.
        object_in_frame1 : :class:`Point` or :class:`Vector` or :class:`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:`Point` or :class:`Vector` or :class:`Frame`
            The object in the local coordinate system of frame2.

        Examples
        --------
        >>> from compas.geometry import Point, Frame
        >>> 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)
Exemple #2
0
    def to_world_coords(self, object_in_lcs):
        """Returns the object's coordinates in the global coordinate frame.

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

        Returns
        -------
        :class:`Point` or :class:`Vector` or :class:`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 Frame
        >>> 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)