project 2 start
This commit is contained in:
parent
858d17efb8
commit
eafd9b4be4
BIN
project2/proj2.pdf
Normal file
BIN
project2/proj2.pdf
Normal file
Binary file not shown.
53
project2/sidedness.py
Normal file
53
project2/sidedness.py
Normal 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
|
Loading…
Reference in New Issue
Block a user