forked from niecongchong/RS-building-regularization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal_dist_ang.py
59 lines (50 loc) · 1.72 KB
/
cal_dist_ang.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
import numpy as np
import math
# 计算两点距离
def cal_dist(point_1, point_2):
dist = np.sqrt(np.sum(np.power((point_1-point_2), 2)))
return dist
# 计算两条线的夹角
def cal_ang(point_1, point_2, point_3):
"""
根据三点坐标计算夹角
:param point_1: 点1坐标
:param point_2: 点2坐标
:param point_3: 点3坐标
:return: 返回任意角的夹角值,这里只是返回点2的夹角
"""
a=math.sqrt((point_2[0]-point_3[0])*(point_2[0]-point_3[0])+(point_2[1]-point_3[1])*(point_2[1] - point_3[1]))
b=math.sqrt((point_1[0]-point_3[0])*(point_1[0]-point_3[0])+(point_1[1]-point_3[1])*(point_1[1] - point_3[1]))
c=math.sqrt((point_1[0]-point_2[0])*(point_1[0]-point_2[0])+(point_1[1]-point_2[1])*(point_1[1]-point_2[1]))
A=math.degrees(math.acos((a*a-b*b-c*c)/(-2*b*c)))
B=math.degrees(math.acos((b*b-a*a-c*c)/(-2*a*c)))
C=math.degrees(math.acos((c*c-a*a-b*b)/(-2*a*b)))
return B
# 计算线条的方位角
def azimuthAngle(point_0, point_1):
x1, y1 = point_0
x2, y2 = point_1
if x1 < x2:
if y1 < y2:
ang = math.atan((y2 - y1) / (x2 - x1))
ang = ang * 180 / math.pi
return ang
elif y1 > y2:
ang = math.atan((y1 - y2) / (x2 - x1))
ang = ang * 180 / math.pi
return 90 + (90 - ang)
elif y1==y2:
return 0
elif x1 > x2:
if y1 < y2:
ang = math.atan((y2-y1)/(x1-x2))
ang = ang*180/math.pi
return 90+(90-ang)
elif y1 > y2:
ang = math.atan((y1-y2)/(x1-x2))
ang = ang * 180 / math.pi
return ang
elif y1==y2:
return 0
elif x1==x2:
return 90