Files
@ 92f4748d07b3
Branch filter:
Location: OneEye/src/analyzer/epoint.py - annotation
92f4748d07b3
1.4 KiB
text/x-python
exp: connecting segmented stones into lines vol 2
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 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 __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))
|