예제 #1
0
    def from_quaternion(cls, quaternion):
        """Construct a rotation transformation` from quaternion coefficients.

        Parameters
        ----------
        quaternion : [float, float, float, float] | :class:`compas.geometry.Quaternion`
            Four numbers that represents the four coefficient values of a quaternion.

        Returns
        -------
        :class:`compas.geometry.Rotation`

        Examples
        --------
        >>> from compas.geometry import allclose
        >>> q1 = [0.945, -0.021, -0.125, 0.303]
        >>> R = Rotation.from_quaternion(q1)
        >>> q2 = R.quaternion
        >>> allclose(q1, q2, tol=1e-3)
        True

        """
        R = cls()
        R.matrix = matrix_from_quaternion(quaternion)
        return R
예제 #2
0
파일: frame.py 프로젝트: itaycsguy/compas
    def from_quaternion(cls, quaternion, point=[0, 0, 0]):
        """Construct a frame from a rotation represented by quaternion coefficients.

        Parameters
        ----------
        quaternion : :obj:`list` of :obj:`float`
            Four numbers that represent the four coefficient values of a quaternion.
        point : :obj:`list` of :obj:`float`, optional
            The point of the frame.
            Defaults to [0, 0, 0].

        Returns
        -------
        Frame
            The constructed frame.

        Examples
        --------
        >>> from compas.geometry import Frame
        >>> q1 = [0.945, -0.021, -0.125, 0.303]
        >>> f = Frame.from_quaternion(q1, point = [1., 1., 1.])
        >>> q2 = f.quaternion
        >>> allclose(q1, q2, tol=1e-03)
        True

        """
        R = matrix_from_quaternion(quaternion)
        xaxis, yaxis = basis_vectors_from_matrix(R)
        return cls(point, xaxis, yaxis)
예제 #3
0
def test_matrix_from_quaternion():
    q1 = [0.945, -0.021, -0.125, 0.303]
    R = matrix_from_quaternion(q1)
    r = [[0.7853252073134178, -0.5669097811969227, -0.2487521230892197, 0.0],
         [0.5774003396942752, 0.8156659006893796, -0.0360275751823359, 0.0],
         [0.22332300929163754, -0.11533619742231993, 0.9678968927964832, 0.0],
         [0.0, 0.0, 0.0, 1.0]]
    assert np.allclose(R, r)
예제 #4
0
    def from_quaternion(cls, quaternion):
        """Calculates a ``Rotation`` from quaternion coefficients.

        Args:
            quaternion (:obj:`list` of :obj:`float`): Four numbers that
                represents the four coefficient values of a quaternion.

        Example:
            >>> q1 = [0.945, -0.021, -0.125, 0.303]
            >>> R = Rotation.from_quaternion(q1)
            >>> q2 = R.quaternion
            >>> allclose(q1, q2, tol=1e-3)
            True
        """
        R = matrix_from_quaternion(quaternion)
        return cls(R)
예제 #5
0
    def from_quaternion(cls, quaternion):
        """Calculates a ``Rotation`` from quaternion coefficients.

        Parameters
        ----------
        quaternion : :class:`Quaternion`
            Four numbers that represents the four coefficient values of a quaternion.

        Examples
        --------
        >>> q1 = [0.945, -0.021, -0.125, 0.303]
        >>> R = Rotation.from_quaternion(q1)
        >>> q2 = R.quaternion
        >>> allclose(q1, q2, tol=1e-3)
        True
        """
        R = matrix_from_quaternion(quaternion)
        return cls(R)
예제 #6
0
    def from_quaternion(cls, quaternion):
        """Calculates a ``Rotation`` from quaternion coefficients.

        Parameters
        ----------
        quaternion : compas.geometry.Quaternion or list
            Four numbers that represents the four coefficient values of a quaternion.

        Examples
        --------
        >>> from compas.geometry import allclose
        >>> q1 = [0.945, -0.021, -0.125, 0.303]
        >>> R = Rotation.from_quaternion(q1)
        >>> q2 = R.quaternion
        >>> allclose(q1, q2, tol=1e-3)
        True
        """
        R = cls()
        R.matrix = matrix_from_quaternion(quaternion)
        return R
예제 #7
0
def test_quaternion_from_matrix():
    q1 = [0.945, -0.021, -0.125, 0.303]
    R = matrix_from_quaternion(q1)
    q2 = quaternion_from_matrix(R)
    assert allclose(q1, q2, tol=1e-03)