PNG2DWG/utils/tools.py

55 lines
1.4 KiB
Python

def caculate_length(dot1,dot2):
import math
length_pingfang = (dot1[0]-dot2[0])**2+(dot1[1]-dot2[1])**2
length = math.sqrt(length_pingfang)
return length
import math
# A(1,-3)B(5,-1)C(4,1)D(4.5,4.5)
def angle(v1):
v2 = [0, 0, 1, 0]
dx1 = v1[2] - v1[0]
dy1 = v1[3] - v1[1]
dx2 = v2[2] - v2[0]
dy2 = v2[3] - v2[1]
angle1 = math.atan2(dy1, dx1)
angle1 = int(angle1 * 180 / math.pi)
# print(angle1)
angle2 = math.atan2(dy2, dx2)
angle2 = int(angle2 * 180 / math.pi)
# print(angle2)
if angle1 * angle2 >= 0:
included_angle = abs(angle1 - angle2)
else:
included_angle = abs(angle1) + abs(angle2)
if included_angle > 180:
included_angle = 360 - included_angle
return included_angle
# 计算方位角函数
def azimuthAngle( x1, y1, x2, y2):
import math
angle = 0.0
dx = x2 - x1
dy = y2 - y1
if x2 == x1:
angle = math.pi / 2.0
if y2 == y1 :
angle = 0.0
elif y2 < y1 :
angle = 3.0 * math.pi / 2.0
elif x2 > x1 and y2 > y1:
angle = math.atan(dx / dy)
elif x2 > x1 and y2 < y1 :
angle = math.pi / 2 + math.atan(-dy / dx)
elif x2 < x1 and y2 < y1 :
angle = math.pi + math.atan(dx / dy)
elif x2 < x1 and y2 > y1 :
angle = 3.0 * math.pi / 2.0 + math.atan(dy / -dx)
return int(angle * 180 / math.pi)