| |
- angle
- exceptions.ValueError(exceptions.StandardError)
-
- ConflictingAngle
- UninitializedAngle
class angle |
|
A class to deal with angles in their various units.
The constructor expects either a radian value (rad=x), a decimal degree value
(deg=x), or a degree-minute-second tuple (deg=(d, m, s), but it can have more or
fewer components). If the argument name is missing it defaults to radians,
unless the value is a tuple, when it defaults to degrees.
>>> angle(3.14)
angle(rad=3.140000, deg=179d54'31.492")
>>> angle(deg=(23, 56, 4, 6))
angle(rad=0.417735, deg=23d56'4.100")
>>> angle((30,))
angle(rad=0.523599, deg=30d0'0.000")
You can add and subtract angles with each other; you can multiply an angle by a
scalar and vice versa; you can divide to angles to get a scalar, and divide an
angle by a scalar to get an angle. You can't divide a scalar by an angle.
>>> angle(rad=pi) - angle(deg=90)
angle(rad=1.570796, deg=90d0'0.000")
>>> 1/angle(pi)
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for /: 'int' and 'instance'
Each trigonometric function has its own method. |
|
Methods defined here:
- SettleConflict(self, deg, rad)
- ToDms(self)
- __add__(self, other)
- __div__(self, other)
- __float__(self)
- __floordiv__(self, other)
- __iadd__(self, other)
- __idiv__(self, other)
- __ifloordiv__(self, other)
- __imod__(self, other)
- __imul__(self, other)
- __init__(self, rad=None, deg=None)
- Initialize an angle with a value in either radians (default) or degrees.
You can specify both, but the values must be compatible (to about 10 decimal
places in radians) or you will raise a 'ConflictingAngle' ValueError. See
SettleConflict() for details. You can also specify neither, but such an instance
will raise an 'Uninitialized' ValueError on any call to getDeg() or getRad().
>>> angle(pi/6, 30)
angle(rad=0.523599, deg=29d59'60.000")
>>> angle(1.571, 90)
Traceback (most recent call last):
...
ConflictingAngle: rad = 1.571, deg = 90.0
>>> angle() + angle()
Traceback (most recent call last):
...
UninitializedAngle
- __isub__(self, other)
- __itruediv__(self, other)
- __mod__(self, other)
- __mul__(self, other)
- __neg__(self)
- __pos__(self)
- __repr__(self)
- __rmul__(self, other)
- __sub__(self, other)
- __truediv__(self, other)
- cos(self)
- cot(self)
- csc(self)
- getDeg(self)
- getRad(self)
- sec(self)
- setDeg(self, deg)
- setRad(self, rad)
- sin(self)
- tan(self)
| |