comparison python/moving.py @ 98:b85912ab4064

refactored projection functions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 12 Jul 2011 16:43:33 -0400
parents b3a1c26e2f22
children 13187af8622d
comparison
equal deleted inserted replaced
97:b3a1c26e2f22 98:b85912ab4064
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 '''Libraries for moving objects, trajectories...''' 2 '''Libraries for moving objects, trajectories...'''
3 3
4 import utils; 4 import utils;
5 import cvutils;
5 6
6 from math import sqrt, hypot; 7 from math import sqrt, hypot;
7 8
8 #from shapely.geometry import Polygon 9 #from shapely.geometry import Polygon
9 10
120 121
121 def __str__(self): 122 def __str__(self):
122 return '(%f,%f)'%(self.x,self.y) 123 return '(%f,%f)'%(self.x,self.y)
123 124
124 def __repr__(self): 125 def __repr__(self):
125 return str(self) 126 return self.__str__()
126 127
127 def __sub__(self, other): 128 def __sub__(self, other):
128 return Point(self.x-other.x, self.y-other.y) 129 return Point(self.x-other.x, self.y-other.y)
129 130
130 def draw(self, options = ''): 131 def draw(self, options = ''):
139 '2-norm distance (Euclidean distance)' 140 '2-norm distance (Euclidean distance)'
140 return sqrt(self.norm2Squared()) 141 return sqrt(self.norm2Squared())
141 142
142 def aslist(self): 143 def aslist(self):
143 return [self.x, self.y] 144 return [self.x, self.y]
145
146 def project(self, homography):
147 from numpy.core.multiarray import array
148 projected = cvutils.projectArray(homography, array([[self.x], [self.y]]))
149 return Point(projected[0], projected[1])
144 150
145 def inPolygon(self, poly): 151 def inPolygon(self, poly):
146 '''Returns if the point x, y is inside the polygon. 152 '''Returns if the point x, y is inside the polygon.
147 The polygon is defined by the ordered list of points in poly 153 The polygon is defined by the ordered list of points in poly
148 154