FanLocalDrawer.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import math
  2. import ezdxf
  3. import core
  4. class FanLocalDrawer:
  5. def __init__(self, msp, layer, gap, center, route):
  6. self.msp = msp
  7. self.gap = gap
  8. self.center = center
  9. self.route = route
  10. self.layer = layer
  11. # a2
  12. # ___a3
  13. # |
  14. # a1
  15. def draw_fan_local(self):
  16. rad = 0.5 * self.gap
  17. self.msp.add_circle(center=self.center, radius=rad, dxfattribs={"layer": f"图层{self.layer}"})
  18. a1 = self.center[0], self.center[1] + rad
  19. a2 = self.center[0], self.center[1] + rad * 3 / 2
  20. a3 = self.center[0] + rad * 1 / 2, self.center[1] + rad * 3 / 2
  21. a1 = core.rotate_point_around_another(a1, self.center, self.route)
  22. a2 = core.rotate_point_around_another(a2, self.center, self.route)
  23. a3 = core.rotate_point_around_another(a3, self.center, self.route)
  24. self.msp.add_line(a1, a2, dxfattribs={"layer": f"图层{self.layer}"})
  25. self.msp.add_line(a2, a3, dxfattribs={"layer": f"图层{self.layer}"})
  26. a4 = core.rotate_point_around_another(a1, self.center, -2/3*math.pi)
  27. a5 = core.rotate_point_around_another(a2, self.center, -2/3*math.pi)
  28. a6 = core.rotate_point_around_another(a3, self.center, -2/3*math.pi)
  29. self.msp.add_line(a4, a5, dxfattribs={"layer": f"图层{self.layer}"})
  30. self.msp.add_line(a5, a6, dxfattribs={"layer": f"图层{self.layer}"})
  31. a7 = core.rotate_point_around_another(a1, self.center, 2/3*math.pi)
  32. a8 = core.rotate_point_around_another(a2, self.center, 2/3*math.pi)
  33. a9 = core.rotate_point_around_another(a3, self.center, 2/3*math.pi)
  34. self.msp.add_line(a7, a8, dxfattribs={"layer": f"图层{self.layer}"})
  35. self.msp.add_line(a8, a9, dxfattribs={"layer": f"图层{self.layer}"})
  36. doc = ezdxf.new("R2013")
  37. msp = doc.modelspace()
  38. fl = FanLocalDrawer(msp,1,5,(90,80),1.114514)
  39. fl.draw_fan_local()
  40. doc.saveas("123.dxf")