/
test.py
60 lines (47 loc) · 1.45 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python2
import numpy as np
from sympy.geometry import Point, Triangle,Line, intersection
fd = open("input6.txt")
lines = fd.readlines()
fd.close()
points = {}
def onbounds(p,a,b,c):
if Line(a,b).contains(p) or Line(b,c).contains(p) or Line(c,a).contains(p):
return True
return False
def incircle( p,a,b,c):
p = points[p]
a = points[a]
b = points[b]
c = points[c]
t = Triangle(a,b,c)
if hasattr(t, "circumcircle") and t.circumcircle.encloses_point( p ):
return 1
if hasattr(t, "circumcircle") and intersection(t.circumcenter,p): #and t.circumcenter.distance(p) == t.circumradius:
return 0
return -1
def intri( p,a,b,c):
p = points[p]
a = points[a]
b = points[b]
c = points[c]
t = Triangle(a,b,c)
if hasattr(t, "encloses_point") and t.encloses_point( p ):
return 1
if onbounds(p,a,b,c):
return 0
return -1
for line in lines:
line = line.split()
if line[1] == "AP":
points[len(points)+1] = Point( long(line[2]),long(line[3]) )
if line[1] == "IT":
print line[0], intri(int(line[2]),
int(line[3]),
int(line[4]),
int(line[5]))
if line[1] == "IC":
print line[0], incircle(int(line[2]),
int(line[3]),
int(line[4]),
int(line[5]))