project 2 start

This commit is contained in:
Thomas Carlsen 2018-09-12 10:21:50 +02:00
parent 858d17efb8
commit eafd9b4be4
2 changed files with 53 additions and 0 deletions

BIN
project2/proj2.pdf Normal file

Binary file not shown.

53
project2/sidedness.py Normal file
View File

@ -0,0 +1,53 @@
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