-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointRelative.py
64 lines (50 loc) · 1.3 KB
/
PointRelative.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
61
62
63
64
from MathHelper import determinant as dt
def is_left(line, point):
assert len(line) == 2
assert len(point) == 2
return dt(line[0], line[1], point) < 0
def on_line(line, point):
assert len(line) == 2
assert len(point) == 2
return dt(line[0], line[1], point) == 0
def is_right(line, point):
assert len(line) == 2
assert len(point) == 2
return dt(line[0], line[1], point) > 0
def is_left(point1, point2, point):
assert len(point) == 2
assert len(point1) == 2
assert len(point2) == 2
return dt(point1, point2, point) < 0
def on_line(point1, point2, point):
assert len(point) == 2
assert len(point1) == 2
assert len(point2) == 2
return dt(point1, point2, point) == 0
def is_right(point1, point2, point):
assert len(point) == 2
assert len(point1) == 2
assert len(point2) == 2
return dt(point1, point2, point) > 0
def point_relative(p1, p2, p):
assert len(p) == 2
assert len(p1) == 2
assert len(p2) == 2
"""
p1p2 (l) - line
p - point
:param p1:
:param p2:
:param p:
:return: -1 if P left to l
1 if P right to l
0 if P on the l
"""
d = dt(p1, p2, p)
if d == 0:
return 0
else:
if d > 0:
return 1
else:
return -1