-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (24 loc) · 761 Bytes
/
utils.py
File metadata and controls
32 lines (24 loc) · 761 Bytes
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
import numpy as np
def GetDistance(p1, p2 = None):
if p2 is None:
return np.sqrt((p1.x - 0)**2 + (p1.y - 0)**2)
return np.sqrt((p1.x - p2.x)**2 + (p1.y - p2.y)**2)
def GetSlope(p1, p2):
m = (p2.y - p1.y) / (p2.x - p1.x)
return m
# def GetTriangleArea(e1, e2, e3):
# s = 1/2 * (e1.point_distance + e2.point_distance + e3.point_distance)
# v1 = (s - e1.point_distance)
# v2 = (s - e2.point_distance)
# v3 = (s - e3.point_distance)
# area = np.sqrt(s*v1*v2*v3)
# return area
def GetTriangleArea(p1, p2, p3):
# m = np.array([
# [p1.x, p1.y, 1],
# [p2.x, p2.y, 1],
# [p3.x, p3.y, 1],
# ])
# area = np.linalg.det(m)*0.5
area = 0.5*((p1.x*p2.y + p2.x*p3.y + p3.x*p1.y) - (p2.x*p1.y + p3.x*p2.y + p1.x*p3.y))
return abs(area)