-
Notifications
You must be signed in to change notification settings - Fork 2
/
homog.py
46 lines (35 loc) · 1.28 KB
/
homog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import numpy as np
class Homog(object):
# Note that in the original Driscoll and Kropf refer to
# homog being compatible with `double`. In a Python sense,
# this is actually a complex. In MATLAB, a complex number is-a
# double
# Also, the numpy representation of vectors and matrices is
# just different enough that homog is never quite going to be
# first class.
def __init__(self, z1, z2=np.complex(1.0, 0.0)):
self._numerator = z1
self._denominator = z2
def isinf(self):
# TODO - confirm that this test is correct in python
zero = 0.0 + 0.0j
return (self._denominator == zero) and (self._numerator != zero)
@property
def numerator(self):
return self._numerator
@property
def denominator(self):
return self._denominator
def __complex__(self):
if self.isinf():
# follows the convention in the original MATLAB of returning real infinity
return np.complex(np.inf)
else:
return self._numerator / self._denominator
def __abs__(self):
return self.__complex__().__abs__()
def __str__(self):
return '%s / %s' % (self._numerator, self._denominator)
# TODO __add__
# TODO __radd__
# TODO other operators ...