import cv2 import numpy as np from PIL import Image, ImageDraw class Point2D(object): def __init__(self, x=0., y=0.): self.x = x self.y = y @property def x(self): return self._x @x.setter def x(self, value): self._x = value @property def y(self): return self._y @y.setter def y(self, value): self._y = value def __str__(self): return '(X:{}, Y:{})'.format(self.x, self.y) def __repr__(self): return 'Point({}, {})'.format(self.x, self.y) def slope(self, target): #k = y2-y1/x2-x1 try: return (target.y - self.y) / (target.x - self.x) except ZeroDivisionError: return None def y_segment(self, target): k = self.slope(target) return self.y - k * self.x def line_function(self, target): k = self.slope(target) b = self.y_segment(target) if k: # y = k*x+b def fn(x): return k * x + b else: # if k=None -> k is infinity def fn(x): p1 = Point2D(1., -18.9) p2 = Point2D(1., -17.) p3 = Point2D(1., -13.) fn_x = p1.line_function(p2) if p3.y == fn_x(p3.x): print('Belongs to line')

Advertisements