BerGeo/project2/sidedness.py
2018-09-12 10:21:50 +02:00

53 lines
817 B
Python

import random
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
def sidedness(p1, p2, p3):
eps = 0.00000001
y = p1.y*(p3.x - p2.x)
x = p1.x
a = (p3.y - p2.y)
b = p3.y*(p3.x - p2.x) - a*p3.x
if y - eps < a*x + b < y + eps:
return "ON"
elif y > a*x + b:
return "ABOVE"
else:
return "BELOW"
# test
p1 = Point(4,4)
p2 = Point(0,0)
p3 = Point(5,2)
#print(sidedness(p1, p2, p3))
def genPoint():
a = random.uniform(1, 10)
b = random.uniform(1, 10)
p = []
for i in range(3):
x_i = random.uniform(1, 10)
p_i = Point(x_i, a*x_i + b)
p.append(p_i)
return p
hej = genPoint()
print(hej)
print(sidedness(*hej))
def graham_scan():
3