from core import rotate_point_around_another from ezdxf import math as mt class GateDrawer: def __init__(self, msp, layer, gap, center, route): self.layer = layer self.msp = msp self.gap = gap self.center = center self.route = route def draw_gate(self): grid = 0.8 * self.gap rad = self.gap * 0.8 point_center = self.center route = self.route # 计算第一个门的三个点 gate1_circle_a = (point_center[0] - grid, point_center[1] + rad) gate1_circle_b = (point_center[0] - grid, point_center[1] - rad) gate1_circle_c = (point_center[0] - grid + rad, point_center[1]) # 旋转这些点 gate1_a = rotate_point_around_another(gate1_circle_a, point_center, route) gate1_b = rotate_point_around_another(gate1_circle_b, point_center, route) gate1_c = rotate_point_around_another(gate1_circle_c, point_center, route) # 创建和添加第一个门的弧和线 self.add_gate_part(gate1_a, gate1_b, gate1_c) # 计算第二个门的三个点 gate2_circle_a = (point_center[0] + grid, point_center[1] + rad) gate2_circle_b = (point_center[0] + grid, point_center[1] - rad) gate2_circle_c = (point_center[0] + grid - rad, point_center[1]) # 旋转这些点 gate2_a = rotate_point_around_another(gate2_circle_a, point_center, route) gate2_b = rotate_point_around_another(gate2_circle_b, point_center, route) gate2_c = rotate_point_around_another(gate2_circle_c, point_center, route) # 创建和添加第二个门的弧和线 self.add_gate_part(gate2_a, gate2_b, gate2_c) def add_gate_part(self, start_point, end_point, def_point): carc = mt.arc.ConstructionArc() b = carc.from_3p(start_point=start_point, def_point=def_point, end_point=end_point) self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle, dxfattribs={"layer": f"图层{self.layer}"}) # self.msp.add_lwpolyline([(start_point[0], start_point[1], 1), (end_point[0], end_point[1], 0)], format="xyb", dxfattribs={"layer": f"图层{self.layer}"}) self.msp.add_line(start_point, end_point, dxfattribs={"layer": f"图层{self.layer}"})