Files
@ f85a79f2fd95
Branch filter:
Location: OneEye/src/epoint.py - annotation
f85a79f2fd95
1.4 KiB
text/x-python
added JSON config file
1f1d49c1dbea 1f1d49c1dbea 1f1d49c1dbea 1f1d49c1dbea 1f1d49c1dbea a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c a1b8c202099c | import math
## Euclidean 2D plane point: (x,y).
class EPoint:
def __init__(self,x,y):
self.x=x
self.y=y
def fromTuple(tup): return EPoint(tup[0],tup[1])
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 __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))
|