地物分类项目代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8KB

  1. import numpy as np
  2. import math
  3. # 计算两点距离
  4. def cal_dist(point_1, point_2):
  5. dist = np.sqrt(np.sum(np.power((point_1-point_2), 2)))
  6. return dist
  7. # 计算两条线的夹角
  8. def cal_ang(point_1, point_2, point_3):
  9. """
  10. 根据三点坐标计算夹角
  11. :param point_1: 点1坐标
  12. :param point_2: 点2坐标
  13. :param point_3: 点3坐标
  14. :return: 返回任意角的夹角值,这里只是返回点2的夹角
  15. """
  16. 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]))
  17. 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]))
  18. 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]))
  19. A=math.degrees(math.acos((a*a-b*b-c*c)/(-2*b*c)))
  20. B=math.degrees(math.acos((b*b-a*a-c*c)/(-2*a*c)))
  21. C=math.degrees(math.acos((c*c-a*a-b*b)/(-2*a*b)))
  22. return B
  23. # 计算线条的方位角
  24. def azimuthAngle(point_0, point_1):
  25. x1, y1 = point_0
  26. x2, y2 = point_1
  27. if x1 < x2:
  28. if y1 < y2:
  29. ang = math.atan((y2 - y1) / (x2 - x1))
  30. ang = ang * 180 / math.pi # 线条的方位角是线条的逆时针方向与水平方向的夹角
  31. return ang
  32. elif y1 > y2:
  33. ang = math.atan((y1 - y2) / (x2 - x1))
  34. ang = ang * 180 / math.pi
  35. return 90 + (90 - ang)
  36. elif y1 == y2:
  37. return 0
  38. elif x1 > x2:
  39. if y1 < y2:
  40. ang = math.atan((y2-y1)/(x1-x2))
  41. ang = ang*180/math.pi
  42. return 90+(90-ang)
  43. elif y1 > y2:
  44. ang = math.atan((y1-y2)/(x1-x2))
  45. ang = ang * 180 / math.pi
  46. return ang
  47. elif y1 == y2:
  48. return 0
  49. elif x1 == x2:
  50. return 90