Example #1
0
    def from_axis_and_angle(cls, axis, angle, point=[0, 0, 0]):
        """Calculates a ``Rotation`` from a rotation axis and an angle and an optional point of rotation.

        The rotation is based on the right hand rule, i.e. anti-clockwise if the
        axis of rotation points towards the observer.

        Parameters
        ----------
        axis : list of float
            Three numbers that represent the axis of rotation.
        angle : float
            The rotation angle in radians.
        point : :class:`Point` or list of float
            A point to perform a rotation around an origin other than [0, 0, 0].

        Examples
        --------
        >>> axis1 = normalize_vector([-0.043, -0.254, 0.617])
        >>> angle1 = 0.1
        >>> R = Rotation.from_axis_and_angle(axis1, angle1)
        >>> axis2, angle2 = R.axis_and_angle
        >>> allclose(axis1, axis2)
        True
        >>> allclose([angle1], [angle2])
        True

        Notes
        -----
        The rotation is based on the right hand rule, i.e. anti-clockwise
        if the axis of rotation points towards the observer.

        """
        R = cls()
        R.matrix = matrix_from_axis_and_angle(axis, angle, point=point)
        return R
Example #2
0
def test_axis_and_angle_from_matrix():
    axis1 = normalize_vector([-0.043, -0.254, 0.617])
    angle1 = 0.1
    R = matrix_from_axis_and_angle(axis1, angle1)
    axis2, angle2 = axis_and_angle_from_matrix(R)
    assert allclose(axis1, axis2)
    assert allclose([angle1], [angle2])
Example #3
0
    def from_axis_and_angle(cls, axis, angle, point=[0, 0, 0]):
        """Calculates a ``Rotation`` from a rotation axis and an angle and \
            an optional point of rotation.

        Note:
            The rotation is based on the right hand rule, i.e. anti-clockwise
            if the axis of rotation points towards the observer.

        Args:
            axis (:obj:`list` of :obj:`float`): Three numbers that represent
                the axis of rotation
            angle (:obj:`float`): The rotation angle in radians.
            point (:obj:`list` of :obj:`float`, optional): A point to
                perform a rotation around an origin other than [0, 0, 0].

        Example:
            >>> axis1 = normalize_vector([-0.043, -0.254, 0.617])
            >>> angle1 = 0.1
            >>> R = Rotation.from_axis_and_angle(axis1, angle1)
            >>> axis2, angle2 = R.axis_and_angle
            >>> allclose(axis1, axis2)
            True
            >>> allclose([angle1], [angle2])
            True
        """
        M = matrix_from_axis_and_angle(axis, angle, point)
        return cls(M)
Example #4
0
def test_matrix_from_axis_angle_vector():
    axis1 = normalize_vector([-0.043, -0.254, 0.617])
    angle1 = 0.1
    R = matrix_from_axis_and_angle(axis1, angle1)
    r = [[0.9950248278789664, -0.09200371122722178, -0.03822183963195913, 0.0],
         [0.09224781823368366, 0.9957251324831573, 0.004669108322156158, 0.0],
         [
             0.037628871037522216, -0.008171760019527692, 0.9992583701939277,
             0.0
         ], [0.0, 0.0, 0.0, 1.0]]
    assert np.allclose(R, r)
Example #5
0
def rotate_points(points, angle, axis=None, origin=None):
    """Rotates points around an arbitrary axis in 3D.

    Parameters
    ----------
    points : list of point
        A list of points.
    angle : float
        The angle of rotation in radians.
    axis : vector, optional
        The rotation axis.
        Default is ``[0.0, 0.0, 1.0]``
    origin : point, optional
        The origin of the rotation axis.
        Default is ``[0.0, 0.0, 0.0]``.

    Returns
    -------
    list of point
        The rotated points

    Examples
    --------
    >>>

    Notes
    -----
    For more info, see [1]_.

    References
    ----------
    .. [1] Wikipedia. *Rotation matrix*.
           Available at: https://en.wikipedia.org/wiki/Rotation_matrix.

    """
    if axis is None:
        axis = [0.0, 0.0, 1.0]
    if origin is None:
        origin = [0.0, 0.0, 0.0]

    R = matrix_from_axis_and_angle(axis, angle, origin)
    points = transform_points(points, R)
    return points
Example #6
0
    def from_axis_and_angle(cls, axis, angle, point=[0, 0, 0]):
        """Construct a rotation transformation from a rotation axis and an angle and an optional point of rotation.

        The rotation is based on the right hand rule, i.e. anti-clockwise if the
        axis of rotation points towards the observer.

        Parameters
        ----------
        axis : [float, float, float] | :class:`compas.geometry.Vector`
            Three numbers that represent the axis of rotation.
        angle : float
            The rotation angle in radians.
        point : [float, float, float] | :class:`compas.geometry.Point`
            A point to perform a rotation around an origin other than [0, 0, 0].

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

        Notes
        -----
        The rotation is based on the right hand rule, i.e. anti-clockwise
        if the axis of rotation points towards the observer.

        Examples
        --------
        >>> axis1 = normalize_vector([-0.043, -0.254, 0.617])
        >>> angle1 = 0.1
        >>> R = Rotation.from_axis_and_angle(axis1, angle1)
        >>> axis2, angle2 = R.axis_and_angle
        >>> allclose(axis1, axis2)
        True
        >>> allclose([angle1], [angle2])
        True

        """
        R = cls()
        R.matrix = matrix_from_axis_and_angle(axis, angle, point=point)
        return R