GateDrawer.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from core import rotate_point_around_another
  2. from ezdxf import math as mt
  3. class GateDrawer:
  4. def __init__(self, msp, gap,center,route):
  5. self.msp = msp
  6. self.gap = gap
  7. self.center = center
  8. self.route = route
  9. def draw_gate(self):
  10. grid = 1.125 * self.gap
  11. rad = self.gap / 0.75
  12. point_center = self.center
  13. route = self.route
  14. # 计算第一个门的三个点
  15. gate1_circle_a = (point_center[0] - grid, point_center[1] + rad)
  16. gate1_circle_b = (point_center[0] - grid, point_center[1] - rad)
  17. gate1_circle_c = (point_center[0] - grid + rad, point_center[1])
  18. # 旋转这些点
  19. gate1_a = rotate_point_around_another(gate1_circle_a, point_center, route)
  20. gate1_b = rotate_point_around_another(gate1_circle_b, point_center, route)
  21. gate1_c = rotate_point_around_another(gate1_circle_c, point_center, route)
  22. # 创建和添加第一个门的弧和线
  23. self.add_gate_part(gate1_a, gate1_b, gate1_c)
  24. # 计算第二个门的三个点
  25. gate2_circle_a = (point_center[0] + grid, point_center[1] + rad)
  26. gate2_circle_b = (point_center[0] + grid, point_center[1] - rad)
  27. gate2_circle_c = (point_center[0] + grid - rad, point_center[1])
  28. # 旋转这些点
  29. gate2_a = rotate_point_around_another(gate2_circle_a, point_center, route)
  30. gate2_b = rotate_point_around_another(gate2_circle_b, point_center, route)
  31. gate2_c = rotate_point_around_another(gate2_circle_c, point_center, route)
  32. # 创建和添加第二个门的弧和线
  33. self.add_gate_part(gate2_a, gate2_b, gate2_c)
  34. def add_gate_part(self, start_point, end_point, def_point):
  35. carc = mt.arc.ConstructionArc() # 假设这是一个可用的类
  36. b = carc.from_3p(start_point=start_point, def_point=def_point, end_point=end_point)
  37. self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle)
  38. self.msp.add_line(start_point, end_point)