示例#1
0
文件: frame.py 项目: yijiangh/compas
    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
示例#2
0
文件: frame.py 项目: itaycsguy/compas
    def euler_angles(self, static=True, axes='xyz'):
        """The Euler angles from the rotation given by the frame.

        Parameters
        ----------
        static : :obj:`bool`, optional
            If true the rotations are applied to a static frame.
            If not, to a rotational.
            Defaults to True.
        axes : :obj:`str`, optional
            A 3 character string specifying the order of the axes.
            Defaults to 'xyz'.

        Returns
        -------
        :obj:`list` of :obj:`float`
            Three numbers that represent the angles of rotations about the defined axes.

        Examples
        --------
        >>> from compas.geometry import Frame
        >>> ea1 = 1.4, 0.5, 2.3
        >>> f = Frame.from_euler_angles(ea1, static = True, axes = 'xyz')
        >>> ea2 = f.euler_angles(static = True, axes = 'xyz')
        >>> allclose(ea1, ea2)
        True

        """
        R = matrix_from_basis_vectors(self.xaxis, self.yaxis)
        return euler_angles_from_matrix(R, static, axes)
示例#3
0
文件: frame.py 项目: yijiangh/compas
    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
示例#4
0
def test_matrix_from_basis_vectors():
    xaxis = [0.68, 0.68, 0.27]
    yaxis = [-0.67, 0.73, -0.15]
    R = matrix_from_basis_vectors(xaxis, yaxis)
    r = [[0.6807833515407016, -0.6687681611113407, -0.29880282253789103, 0.0],
         [0.6807833515407016, 0.7282315114847181, -0.07882160714891209, 0.0],
         [0.2703110366411609, -0.14975954908850603, 0.9510541192112079, 0.0],
         [0.0, 0.0, 0.0, 1.0]]
    assert np.allclose(R, r)
示例#5
0
文件: frame.py 项目: itaycsguy/compas
 def axis_angle_vector(self):
     """vector : The axis-angle vector from the rotation given by the frame."""
     R = matrix_from_basis_vectors(self.xaxis, self.yaxis)
     return Vector(*axis_angle_vector_from_matrix(R))
示例#6
0
文件: frame.py 项目: itaycsguy/compas
 def quaternion(self):
     """:class:`Quaternion` : The quaternion from the rotation given by the frame.
     """
     rotation = matrix_from_basis_vectors(self.xaxis, self.yaxis)
     return Quaternion(*quaternion_from_matrix(rotation))
示例#7
0
文件: frame.py 项目: yijiangh/compas
 def quaternion(self):
     """:obj:`list` of :obj:`float` : The 4 quaternion coefficients from the rotation given by the frame.
     """
     rotation = matrix_from_basis_vectors(self.xaxis, self.yaxis)
     return quaternion_from_matrix(rotation)