地物分类项目代码
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.

51 lines
1.2KB

  1. from __future__ import division
  2. import numpy as np
  3. # 线生成函数,p1的坐标为(x1, y1),p2的坐标为(x2, y2)
  4. def line(p1, p2):
  5. A = (p1[1] - p2[1])
  6. B = (p2[0] - p1[0])
  7. C = (p1[0]*p2[1] - p2[0]*p1[1])
  8. return A, B, -C
  9. # 计算两条直线之间的交点
  10. def intersection(L1, L2):
  11. D = L1[0] * L2[1] - L1[1] * L2[0]
  12. Dx = L1[2] * L2[1] - L1[1] * L2[2]
  13. Dy = L1[0] * L2[2] - L1[2] * L2[0]
  14. if D != 0:
  15. x = Dx / D
  16. y = Dy / D
  17. return x, y
  18. else:
  19. return False
  20. # 计算两个平行线之间的距离
  21. def par_line_dist(L1, L2):
  22. A1, B1, C1 = L1
  23. A2, B2, C2 = L2
  24. new_A1 = 1
  25. new_B1 = B1 / A1
  26. new_C1 = C1 / A1
  27. new_A2 = 1
  28. new_B2 = B2 / A2
  29. new_C2 = C2 / A2
  30. dist = (np.abs(new_C1-new_C2))/(np.sqrt(new_A2*new_A2+new_B2*new_B2))
  31. return dist
  32. # 计算点在直线的投影位置
  33. def point_in_line(m, n, x1, y1, x2, y2):
  34. x = (m * (x2 - x1) * (x2 - x1) + n * (y2 - y1) * (x2 - x1) + (x1 * y2 - x2 * y1) * (y2 - y1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
  35. y = (m * (x2 - x1) * (y2 - y1) + n * (y2 - y1) * (y2 - y1) + (x2 * y1 - x1 * y2) * (x2 - x1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
  36. return (x, y)