Some code sample for 2d-point

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

	def x(self):
		return self._x

	def x(self, value):
		self._x = value

	def y(self):
		return self._y

	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
			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

			# 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')

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s