Beispiel #1
0
def atan(scalar):
    """ atan

    >>> scalar = ETQ.Scalar(0.5)
    >>> print(scalar)
       0.500  (Scalar)
    >>> print(atan(scalar.get_value()))  # rad
    0.46364760900...
    >>> print(atan(scalar.get_uval()))
      26.565 deg (Angle)
    >>> a=atan(scalar); a.set_displayUnit('deg'); print(a)
      26.565 deg (Angle)
    >>> print(atan(ETQ.Distance(0.5, 'm')))
    Traceback (most recent call last):
        ...
    EngineeringTools.tools.functions.EngineeringTools_tools_Error_units: wrong type : <class 'EngineeringTools.quantities.mechanics.Distance'>

    """
    if isinstance(scalar, float):
        return _np.arctan(scalar)
    elif isinstance(scalar, ETQ.UVal):
        scalar.check_units({})
        return ETQ.Angle(_np.arctan(scalar.get_value()), 'rad')
    elif isinstance(scalar, ETQ.Scalar):
        return ETQ.Angle(_np.arctan(scalar.get_value()), 'rad')
    else:
        raise EngineeringTools_tools_Error_units('wrong type : %s' % type(scalar))
Beispiel #2
0
 def test__Angle(self):
     A1 = 0.5
     qa = Q.Angle(A1, 'rad', 'deg')
     self.assertEqual(A1, qa.get_value())
     self.assertEqual(A1, qa.get_value(unit='rad'))
     self.assertEqual(qa.get_value(), qa.get_value(unit=qa.get_isoUnit()))
     self.assertAlmostEqual(A1/math.pi*180, qa.get_value(unit='deg'), 9)
Beispiel #3
0
def arcsin(scalar):
    """ arcsin

    >>> scalar = ETQ.Scalar(0.5, '1.0')
    >>> print(scalar)
       0.500  (Scalar)
    >>> print(asin(scalar.get_value()))  # rad
    0.52359877559...
    >>> asin(scalar.get_uval())
    UVal(0.5235987755982989, {})
    >>> print(asin(scalar.get_uval()))
    0.5236 {}
    >>> a=asin(scalar); a.set_displayUnit('deg'); print(a)
      30.000 deg (Angle)
    >>> print(asin(ETQ.Distance(0.5, 'm')))
    Traceback (most recent call last):
        ...
    EngineeringTools.tools.functions.EngineeringTools_tools_Error_units: wrong type : <class 'EngineeringTools.quantities.mechanics.Distance'>

    """
    if isinstance(scalar, float):
        return _np.arcsin(scalar)
    elif isinstance(scalar, ETQ.UVal):
        scalar.check_units({})
        return ETQ.UVal(_np.arcsin(scalar.get_value()), {})
    elif isinstance(scalar, ETQ.Scalar):
        return ETQ.Angle(_np.arcsin(scalar.get_value()), 'rad')
    else:
        raise EngineeringTools_tools_Error_units('wrong type : %s' % type(scalar))
Beispiel #4
0
def atan2(y, x):
    """ atan2

    >>> y = ETQ.Distance(1/3.0**(0.5), 'm')
    >>> x = ETQ.Distance(1.0, 'm')
    >>> print(y, x)
     577.350 mm (Distance) 1000.000 mm (Distance)
    >>> print(atan2(y, x))
      30.000 deg (Angle)
    >>> atan2(y.uval, x.uval)
    UVal(0.5235987755982989, {})
    >>> print(atan2(y.value, x.value) / _np.pi * 180.0)
    30.0...

    """
    if isinstance(y, float) and isinstance(x, float):
        return _np.arctan2(y, x)
    elif isinstance(y, ETQ.UVal) and isinstance(x, ETQ.UVal):
        y.check_units(x)
        return ETQ.UVal(_np.arctan2(y.get_value(), x.get_value()), {})
    elif y.match_quantities(x):
        return ETQ.Angle(_np.arctan2(y.get_value(), x.get_value()), 'rad')
    else:
        raise EngineeringTools_tools_Error_units('wrong type or combination : %s, %s' % (type(y), type(x)))