Exemplo n.º 1
0
    def __init__(self, arg=None, *, unit='rad', check=True):
        """
        Construct new SO(2) object

        :param unit: angular units 'deg' or 'rad' [default] if applicable
        :type unit: str, optional
        :param check: check for valid SO(2) elements if applicable, default to True
        :type check: bool
        :return: SO(2) rotation
        :rtype: SO2 instance

        - ``SO2()`` is an SO2 instance representing a null rotation -- the identity matrix.
        - ``SO2(θ)`` is an SO2 instance representing a rotation by ``θ`` radians.  If ``θ`` is array_like
          `[θ1, θ2, ... θN]` then an SO2 instance containing a sequence of N rotations.
        - ``SO2(θ, unit='deg')`` is an SO2 instance representing a rotation by ``θ`` degrees.  If ``θ`` is array_like
          `[θ1, θ2, ... θN]` then an SO2 instance containing a sequence of N rotations.
        - ``SO2(R)`` is an SO2 instance with rotation described by the SO(2) matrix R which is a 2x2 numpy array.  If ``check``
          is ``True`` check the matrix belongs to SO(2).
        - ``SO2([R1, R2, ... RN])`` is an SO2 instance containing a sequence of N rotations, each described by an SO(2) matrix
          Ri which is a 2x2 numpy array. If ``check`` is ``True`` then check each matrix belongs to SO(2).
        - ``SO2([X1, X2, ... XN])`` is an SO2 instance containing a sequence of N rotations, where each Xi is an SO2 instance.

        """
        if  super().arghandler(arg, check=check):
            return

        elif argcheck.isscalar(arg):
            self.data = [tr.rot2(arg, unit=unit)]

        elif argcheck.isvector(arg):
            self.data = [tr.rot2(x, unit=unit) for x in argcheck.getvector(arg)]

        else:
            raise ValueError('bad argument to constructor')
Exemplo n.º 2
0
 def __init__(self, arg = None, *, unit='rad'):
     super().__init__()  # activate the UserList semantics
     
     if arg is None:
         # empty constructor
         self.data = [np.eye(2)]
     
     elif argcheck.isvector(arg):
         # SO2(value)
         # SO2(list of values)
         self.data = [tr.rot2(x, unit) for x in argcheck.getvector(arg)]
         
     else:
         super().arghandler(arg)
Exemplo n.º 3
0
    def __init__(self, arg=None, *, unit='rad'):
        super().__init__()  # activate the UserList semantics

        if arg is None:
            # empty constructor
            if type(self) is SO2:
                self.data = [np.eye(2)]

        elif argcheck.isvector(arg):
            # SO2(value)
            # SO2(list of values)
            self.data = [tr.rot2(x, unit) for x in argcheck.getvector(arg)]

        elif isinstance(arg, np.ndarray) and arg.shape == (2, 2):
            self.data = [arg]
        else:
            super().arghandler(arg)
Exemplo n.º 4
0
    def __init__(self, arg=None, *, unit='rad', check=True):
        """
        Construct new SO(2) object

        :param unit: angular units 'deg' or 'rad' [default] if applicable
        :type unit: str, optional
        :param check: check for valid SO(2) elements if applicable, default to True
        :type check: bool
        :return: SO(2) rotation
        :rtype: SO2 instance

        - ``SO2()`` is an SO2 instance representing a null rotation -- the identity matrix.
        - ``SO2(theta)`` is an SO2 instance representing a rotation by ``theta`` radians.  If ``theta`` is array_like
          `[theta1, theta2, ... thetaN]` then an SO2 instance containing a sequence of N rotations.
        - ``SO2(theta, unit='deg')`` is an SO2 instance representing a rotation by ``theta`` degrees.  If ``theta`` is array_like
          `[theta1, theta2, ... thetaN]` then an SO2 instance containing a sequence of N rotations.
        - ``SO2(R)`` is an SO2 instance with rotation described by the SO(2) matrix R which is a 2x2 numpy array.  If ``check``
          is ``True`` check the matrix belongs to SO(2).
        - ``SO2([R1, R2, ... RN])`` is an SO2 instance containing a sequence of N rotations, each described by an SO(2) matrix
          Ri which is a 2x2 numpy array. If ``check`` is ``True`` then check each matrix belongs to SO(2).
        - ``SO2([X1, X2, ... XN])`` is an SO2 instance containing a sequence of N rotations, where each Xi is an SO2 instance.
        
        """
        super().__init__()  # activate the UserList semantics

        if arg is None:
            # empty constructor
            if type(self) is SO2:
                self.data = [np.eye(2)]
        elif argcheck.isvector(arg):
            # SO2(value)
            # SO2(list of values)
            self.data = [tr.rot2(x, unit) for x in argcheck.getvector(arg)]

        elif isinstance(arg, np.ndarray) and arg.shape == (2, 2):
            self.data = [arg]
        else:
            super()._arghandler(arg, check=check)
    def Rand(cls, N=1, arange=(0, 2 * math.pi), unit='rad'):
        r"""
        Construct new SO(2) with random rotation

        :param arange: rotation range, defaults to :math:`[0, 2\pi)`.
        :type arange: 2-element array-like, optional
        :param unit: angular units as 'deg or 'rad' [default]
        :type unit: str, optional
        :param N: number of random rotations, defaults to 1
        :type N: int
        :return: SO(2) rotation matrix
        :rtype: SO2 instance

        - ``SO2.Rand()`` is a random SO(2) rotation.
        - ``SO2.Rand([-90, 90], unit='deg')`` is a random SO(2) rotation between
          -90 and +90 degrees.
        - ``SO2.Rand(N)`` is a sequence of N random rotations.

        Rotations are uniform over the specified interval.

        """
        rand = np.random.uniform(low=arange[0], high=arange[1], size=N)  # random values in the range
        return cls([base.rot2(x) for x in argcheck.getunit(rand, unit)])
Exemplo n.º 6
0
 def rand(cls, *, range=[0, 2 * math.pi], unit='rad', N=1):
     rand = np.random.uniform(low=range[0], high=range[1],
                              size=N)  # random values in the range
     return cls([tr.rot2(x) for x in argcheck.getunit(rand, unit)])