コード例 #1
0
ファイル: frame.py プロジェクト: irfanirw/compas
    def local_to_local_coordinates(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_coordinates(frame1, frame2, p1) # point in frame2
        >>> Frame.local_to_local_coordinates(frame2, frame1, p2)
        Point(2.000, 2.000, 2.000)
        """
        T = Transformation.from_change_of_basis(frame1, frame2)
        if isinstance(object_in_frame1, list):
            return Point(*object_in_frame1).transformed(T)
        return object_in_frame1.transformed(T)
コード例 #2
0
ファイル: frame.py プロジェクト: irfanirw/compas
    def to_world_coordinates(self, object_in_lcf):
        """Returns the object's coordinates in the global coordinate frame.

        Parameters
        ----------
        object_in_lcf : :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_coordinates(pl) # point in wcf
        >>> frame.to_local_coordinates(pw)
        Point(1.632, -0.090, 0.573)
        """
        T = Transformation.from_change_of_basis(self, Frame.worldXY())
        if isinstance(object_in_lcf, list):
            return Point(*object_in_lcf).transformed(T)
        else:
            return object_in_lcf.transformed(T)
コード例 #3
0
ファイル: frame.py プロジェクト: compas-dev/compas
    def to_local_coordinates(self, obj_in_wcf):
        """Returns the object's coordinates in the local coordinate system of the frame.

        Parameters
        ----------
        obj_in_wcf : [float, float, float] | :class:`compas.geometry.Geometry`
            An object in the world coordinate frame.

        Returns
        -------
        :class:`compas.geometry.Geometry`
            The object in the local coordinate system of the frame.

        Notes
        -----
        If you pass a list of floats, 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])
        >>> pw = Point(2, 2, 2) # point in wcf
        >>> pl = frame.to_local_coordinates(pw) # point in frame
        >>> frame.to_world_coordinates(pl)
        Point(2.000, 2.000, 2.000)

        """
        T = Transformation.from_change_of_basis(Frame.worldXY(), self)
        if isinstance(obj_in_wcf, (list, tuple)):
            return Point(*obj_in_wcf).transformed(T)
        return obj_in_wcf.transformed(T)
コード例 #4
0
    def contains(self, point):
        """Verify if the box contains a given point.

        Parameters
        ----------
        point : :class:`compas.geometry.Point` or (float, float, float)

        Returns
        -------
        bool
        """
        T = Transformation.from_change_of_basis(Frame.worldXY(), self.frame)
        point = transform_points([point], T)[0]
        if -0.5 * self.xsize < point[0] < + 0.5 * self.xsize:
            if -0.5 * self.ysize < point[1] < +0.5 * self.ysize:
                if -0.5 * self.zsize < point[2] < +0.5 * self.zsize:
                    return True
        return False
コード例 #5
0
from compas.geometry import Point, Box, Frame, Vector, Plane, scale_vector, normalize_vector, Polygon, Rotation, intersection_line_line
from compas.geometry import Transformation

frame1 = Frame(Point(0, 0), Vector(-1, 0), Vector(0, 1))
frame2 = Frame(Point(10, 0), Vector(-1, 0), Vector(0, 1))

frame3 = Frame(Point(0, 0), Vector(0, 1), Vector(1, 0))

F1 = Transformation.from_change_of_basis(frame1, frame2)

frame4 = frame3.transformed(F1)

print(frame4)
"""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.from_change_of_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_coordinates(F1.point))