Files
@ 90d22d070710
Branch filter:
Location: OneEye/src/analyzer/epoint.py - annotation
90d22d070710
1.8 KiB
text/x-python
refactored line reconstruction
3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 7ef3360afbe5 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 3798475f45c1 92f4748d07b3 92f4748d07b3 92f4748d07b3 92f4748d07b3 92f4748d07b3 90d22d070710 90d22d070710 90d22d070710 90d22d070710 90d22d070710 90d22d070710 90d22d070710 90d22d070710 90d22d070710 90d22d070710 3798475f45c1 3798475f45c1 | import math
## Euclidean 2D plane point: (x,y).
class EPoint:
def __init__(self,x,y):
self.x=x
self.y=y
@staticmethod
def fromProjective(point):
if point.item(0)==0: return None
return EPoint(point.item(1)/point.item(0),point.item(2)/point.item(0))
def toProjective(self):
return (1,self.x,self.y)
def dist(self,a):
return math.sqrt((self.x-a.x)**2+(self.y-a.y)**2)
def __add__(self,a):
return EPoint(self.x+a.x,self.y+a.y)
def __sub__(self,a):
return EPoint(self.x-a.x,self.y-a.y)
def __mul__(self,k):
return EPoint(self.x*k,self.y*k)
def __rmul__(self,k):
return self*k
def __truediv__(self,k):
return EPoint(self.x/k,self.y/k)
def __floordiv__(self,k):
return EPoint(self.x//k,self.y//k)
def __iadd__(self,a):
self.x+=a.x
self.y+=a.y
return self
def __isub__(self,a):
self.x-=a.x
self.y-=a.y
return self
def __imul__(self,k):
self.x*=k
self.y*=k
return self
def __itruediv__(self,k):
self.x/=k
self.y/=k
return self
def __ifloordiv__(self,k):
self.x//=k
self.y//=k
return self
def __neg__(self):
return EPoint(-self.x,-self.y)
def __getitem__(self,key):
if key==0: return self.x
elif key==1: return self.y
raise IndexError(key)
def __hash__(self):
return hash((self.x,self.y))
def __lt__(self,a): return self.x<a.x or (self.x==a.x and self.y<a.y)
def __le__(self,a): return self.x<a.x or (self.x==a.x and self.y<=a.y)
def __gt__(self,a): return self.x>a.x or (self.x==a.x and self.y>a.y)
def __ge__(self,a): return self.x>a.x or (self.x==a.x and self.y>=a.y)
def __eq__(self,a): return self.x==a.x and self.y==a.y
def __ne__(self,a): return self.x!=a.x or self.y!=a.y
def __str__(self): return "({0},{1})".format(round(self.x,3),round(self.y,3))
def __repr__(self): return "EPoint({0},{1})".format(round(self.x,3),round(self.y,3))
|