def bulge2arc(self, Ps, Pe, bulge): """ bulge2arc() """ c = (1 / bulge - bulge) / 2 # Berechnung des Mittelpunkts (Formel von Mickes!) # Calculation of the center (Micke's formula) O = Point((Ps.x + Pe.x - (Pe.y - Ps.y) * c) / 2, (Ps.y + Pe.y + (Pe.x - Ps.x) * c) / 2) # Radius = Distance between the centre and Ps r = O.distance(Ps) # Kontrolle ob beide gleich sind (passt ...) # Check if they are equal (fits ...) # r=O.distance(Pe) # Unterscheidung f�r den �ffnungswinkel. # Distinction for the opening angle. ??? if bulge > 0: return ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r) else: arc = ArcGeo(Ps=Pe, Pe=Ps, O=O, r=r) arc.reverse() return arc
def __init__(self, Ps=None, Pe=None, O=None, r=1, s_ang=None, e_ang=None, direction=1, drag=False): """ Standard Method to initialize the ArcGeo. Not all of the parameters are required to fully define a arc. e.g. Ps and Pe may be given or s_ang and e_ang @param Ps: The Start Point of the arc @param Pe: the End Point of the arc @param O: The center of the arc @param r: The radius of the arc @param s_ang: The Start Angle of the arc @param e_ang: the End Angle of the arc @param direction: The arc direction where 1 is in positive direction """ ArcGeo.__init__(self, Ps=Ps, Pe=Pe, O=O, r=r, s_ang=s_ang, e_ang=e_ang, direction=direction, drag=drag)
def Read(self, caller): """ Read() """ # Assign short name lp = caller.line_pairs e = lp.index_code(0, caller.start + 1) # Assign layer s = lp.index_code(8, caller.start + 1) self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value) # X Value s = lp.index_code(10, s + 1) x0 = float(lp.line_pair[s].value) # Y Value s = lp.index_code(20, s + 1) y0 = float(lp.line_pair[s].value) # Radius s = lp.index_code(40, s + 1) r = float(lp.line_pair[s].value) # Searching for an extrusion direction s_nxt_xt = lp.index_code(230, s + 1, e) # If there is a extrusion direction given flip around x-Axis if s_nxt_xt is not None: extrusion_dir = float(lp.line_pair[s_nxt_xt].value) logger.debug(self.tr('Found extrusion direction: %s') % extrusion_dir) if extrusion_dir == -1: x0 = -x0 O = Point(x0, y0) # Calculate the start and end values of the circle without clipping s_ang = -3 * pi / 4 m_ang = s_ang - pi e_ang = -3 * pi / 4 # Calculate the start and end values of the arcs Ps = Point(cos(s_ang) * r, sin(s_ang) * r) + O Pm = Point(cos(m_ang) * r, sin(m_ang) * r) + O Pe = Point(cos(e_ang) * r, sin(e_ang) * r) + O # Annexes to ArcGeo class for geometry self.geo.append(ArcGeo(Ps=Ps, Pe=Pm, O=O, r=r, s_ang=s_ang, e_ang=m_ang, direction=-1)) self.geo.append(ArcGeo(Ps=Pm, Pe=Pe, O=O, r=r, s_ang=m_ang, e_ang=e_ang, direction=-1)) # Length corresponds to the length (circumference?) of the circle self.length = self.geo[-1].length+self.geo[-2].length # New starting value for the next geometry caller.start = s
def fit_triac_by_inc_biarc(self, arc, eps): """ fit_triac_by_inc_biarc() """ # Errechnen von tb V0 = (arc[0].O - arc[0].Ps).unit_vector() V2 = (arc[2].O - arc[2].Pe).unit_vector() # Errechnen der Hilfgr�ssen t0 = (arc[2].r - arc[0].r) D = (arc[2].O - arc[0].O) X0 = (t0 * t0) - (D * D) X1 = 2 * (D * V0 - t0) Y0 = 2 * (t0 - D * V2) Y1 = 2 * (V0 * V2 - 1) # Errechnen von tb tb = (pow((arc[1].r - arc[0].r + eps), 2) - ((arc[1].O - arc[0].O) * (arc[1].O - arc[0].O))) / \ (2 * (arc[1].r - arc[0].r + eps + (arc[1].O - arc[0].O) * V0)) # Errechnen von tc tc = (pow(t0, 2) - (D * D)) / (2 * (t0 - D * V0)) # Auswahl von t t = min([tb, tc]) # Errechnen von u u = (X0 + X1 * t) / (Y0 + Y1 * t) # Errechnen der neuen Arcs Oa = arc[0].O + t * V0 ra = arc[0].r + t Ob = arc[2].O - u * V2 rb = arc[2].r - u Vn = (Oa - Ob).unit_vector() Pn = Oa + ra * Vn Arc0 = ArcGeo(Ps=arc[0].Ps, Pe=Pn, O=Oa, r=ra, direction=arc[0].ext) Arc1 = ArcGeo(Ps=Pn, Pe=arc[2].Pe, O=Ob, r=rb, direction=arc[2].ext) # print('\nAlte') # print arc[0] # print arc[1] # print arc[2] # print("tb: %0.3f; tc: %0.3f; t: %0.3f; u: %0.3f" %(tb,tc,t,u)) # print 'Neue' # print Arc0 # print Arc1 return Arc0, Arc1
def fit_triac_by_dec_biarc(self, arc, eps): """ fit_triac_by_dec_biarc() """ V0 = (arc[2].O - arc[2].Pe).unit_vector() V2 = (arc[0].O - arc[0].Ps).unit_vector() # Errechnen der Hilfgr�ssen t0 = (arc[0].r - arc[2].r) D = (arc[0].O - arc[2].O) X0 = (t0 * t0) - (D * D) X1 = 2 * (D * V0 - t0) Y0 = 2 * (t0 - D * V2) Y1 = 2 * (V0 * V2 - 1) # Errechnen von tb tb = (pow((arc[1].r - arc[2].r + eps), 2) - ((arc[1].O - arc[2].O) * (arc[1].O - arc[2].O))) / \ (2 * (arc[1].r - arc[2].r + eps + (arc[1].O - arc[2].O) * V0)) # Errechnen von tc tc = (pow(t0, 2) - (D * D)) / (2 * (t0 - D * V0)) # Auswahl von t t = min([tb, tc]) # Errechnen von u u = (X0 + X1 * t) / (Y0 + Y1 * t) # Errechnen der neuen Arcs Oa = arc[0].O - u * V2 ra = arc[0].r - u Ob = arc[2].O + t * V0 rb = arc[2].r + t Vn = (Ob - Oa).unit_vector() Pn = Ob + rb * Vn Arc0 = ArcGeo(Ps=arc[0].Ps, Pe=Pn, O=Oa, r=ra, \ s_ang=Oa.norm_angle(arc[0].Ps), e_ang=Oa.norm_angle(Pn), direction=arc[0].ext) Arc1 = ArcGeo(Ps=Pn, Pe=arc[2].Pe, O=Ob, r=rb, \ s_ang=Ob.norm_angle(Pn), e_ang=Ob.norm_angle(arc[2].Pe), direction=arc[2].ext) return Arc0, Arc1
def breakArcGeo(self, arcGeo): """ Try to break passed arcGeo with any of the shapes on a break layers. Will break arcGeos recursively. @return: The list of geometries after breaking (arcGeo itself if no breaking happened) """ newGeos = Geos([]) for breakLayer in self.breakLayers: for breakShape in breakLayer.shapes.not_disabled_iter(): intersections = self.intersectArcGeometry(arcGeo, breakShape) if len(intersections) == 2: (near, far) = self.classifyIntersections(arcGeo, intersections) logger.debug("Arc %s broken from (%f, %f) to (%f, %f)" % (arcGeo.toShortString(), near.x, near.y, far.x, far.y)) newGeos.extend(self.breakArcGeo(ArcGeo(Ps=arcGeo.Ps, Pe=near, O=arcGeo.O, r=arcGeo.r, s_ang=arcGeo.s_ang, direction=arcGeo.ext))) newGeos.append(BreakGeo(near, far, breakShape.axis3_mill_depth, breakShape.f_g1_plane, breakShape.f_g1_depth)) newGeos.extend(self.breakArcGeo(ArcGeo(Ps=far, Pe=arcGeo.Pe, O=arcGeo.O, r=arcGeo.r, e_ang=arcGeo.e_ang, direction=arcGeo.ext))) return newGeos return [arcGeo]
def bulge2arc(self, Ps, Pe, bulge): """ bulge2arc() """ c = (1 / bulge - bulge) / 2 # Calculate the centre point (Micke's formula!) O = Point((Ps.x + Pe.x - (Pe.y - Ps.y) * c) / 2, (Ps.y + Pe.y + (Pe.x - Ps.x) * c) / 2) # Radius = Distance between the centre and Ps r = O.distance(Ps) # Check if they are equal (fits ...) # r=O.distance(Pe) # Unterscheidung f�r den �ffnungswinkel. # Distinction for the opening angle. ??? if bulge > 0: return ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r) else: arc = ArcGeo(Ps=Pe, Pe=Ps, O=O, r=r) arc.reverse() return arc
def Read(self, caller): """ Read() """ # Assign short name lp = caller.line_pairs e = lp.index_code(0, caller.start + 1) # Assign layer s = lp.index_code(8, caller.start + 1) self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value) # X Value s = lp.index_code(10, s + 1) x0 = float(lp.line_pair[s].value) # Y Value s = lp.index_code(20, s + 1) y0 = float(lp.line_pair[s].value) O = Point(x0, y0) # Radius s = lp.index_code(40, s + 1) r = float(lp.line_pair[s].value) # Start angle s = lp.index_code(50, s + 1) s_ang = radians(float(lp.line_pair[s].value)) # End angle s = lp.index_code(51, s + 1) e_ang = radians(float(lp.line_pair[s].value)) # Searching for an extrusion direction s_nxt_xt = lp.index_code(230, s + 1, e) # If there is a extrusion direction given flip around x-Axis if s_nxt_xt is not None: extrusion_dir = float(lp.line_pair[s_nxt_xt].value) logger.debug(self.tr('Found extrusion direction: %s') % extrusion_dir) if extrusion_dir == -1: x0 = -x0 s_ang = s_ang + pi e_ang = e_ang + pi # Calculate the start and end points of the arcs Ps = Point(cos(s_ang) * r, sin(s_ang) * r) + O Pe = Point(cos(e_ang) * r, sin(e_ang) * r) + O # Anh�ngen der ArcGeo Klasse f�r die Geometrie # Annexes to ArcGeo class for geometry self.geo.append(ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r, s_ang=s_ang, e_ang=e_ang, direction=1)) # L�nge entspricht der L�nge des Kreises # Length is the length (circumference?) of the circle self.length = self.geo[-1].length # logger.debug(self.geo[-1]) # Neuen Startwerd f�r die n�chste Geometrie zur�ckgeben # New starting value for the next geometry caller.start = s
def make_start_moves(self): """ This function called to create the start move. It will be generated based on the given values for start and angle. """ self.geos = Geos([]) if g.config.machine_type == 'drag_knife': self.make_swivelknife_move() return # Get the start rad. and the length of the line segment at begin. start_rad = self.shape.parentLayer.start_radius # Get tool radius based on tool diameter. tool_rad = self.shape.parentLayer.getToolRadius() # Calculate the starting point with and without compensation. start = self.start angle = self.angle if self.shape.cut_cor == 40: self.append(RapidPos(start)) elif self.shape.cut_cor != 40 and not g.config.vars.Cutter_Compensation[ "done_by_machine"]: toolwidth = self.shape.parentLayer.getToolRadius() offtype = "in" if self.shape.cut_cor == 42 else "out" offshape = offShapeClass(parent=self.shape, offset=toolwidth, offtype=offtype) if len(offshape.rawoff) > 0: start, angle = offshape.rawoff[0].get_start_end_points( True, True) self.append(RapidPos(start)) self.geos += offshape.rawoff # Cutting Compensation Left elif self.shape.cut_cor == 41: # Center of the Starting Radius. Oein = start.get_arc_point(angle + pi / 2, start_rad + tool_rad) # Start Point of the Radius Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad) # Start Point of the straight line segment at begin. Pg_ein = Ps_ein.get_arc_point(angle + pi / 2, start_rad) # Get the dive point for the starting contour and append it. start_ein = Pg_ein.get_arc_point(angle, tool_rad) self.append(RapidPos(start_ein)) # generate the Start Line and append it including the compensation. start_line = LineGeo(start_ein, Ps_ein) self.append(start_line) # generate the start rad. and append it. start_rad = ArcGeo(Ps=Ps_ein, Pe=start, O=Oein, r=start_rad + tool_rad, direction=1) self.append(start_rad) # Cutting Compensation Right elif self.shape.cut_cor == 42: # Center of the Starting Radius. Oein = start.get_arc_point(angle - pi / 2, start_rad + tool_rad) # Start Point of the Radius Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad) # Start Point of the straight line segment at begin. Pg_ein = Ps_ein.get_arc_point(angle - pi / 2, start_rad) # Get the dive point for the starting contour and append it. start_ein = Pg_ein.get_arc_point(angle, tool_rad) self.append(RapidPos(start_ein)) # generate the Start Line and append it including the compensation. start_line = LineGeo(start_ein, Ps_ein) self.append(start_line) # generate the start rad. and append it. start_rad = ArcGeo(Ps=Ps_ein, Pe=start, O=Oein, r=start_rad + tool_rad, direction=0) self.append(start_rad)
def make_swivelknife_move(self): """ Set these variables for your tool and material @param offset: knife tip distance from tool centerline. The radius of the tool is used for this. """ offset = self.shape.parentLayer.getToolRadius() drag_angle = self.shape.drag_angle startnorm = offset * Point( 1, 0) # TODO make knife direction a config setting prvend, prvnorm = Point(), Point() first = True for geo in self.shape.geos.abs_iter(): if isinstance(geo, LineGeo): geo_b = deepcopy(geo) if first: first = False prvend = geo_b.Ps + startnorm prvnorm = startnorm norm = offset * (geo_b.Pe - geo_b.Ps).unit_vector() geo_b.Ps += norm geo_b.Pe += norm if not prvnorm == norm: direction = prvnorm.to3D().cross_product(norm.to3D()).z swivel = ArcGeo(Ps=prvend, Pe=geo_b.Ps, r=offset, direction=direction) swivel.drag = drag_angle < abs(swivel.ext) self.append(swivel) self.append(geo_b) prvend = geo_b.Pe prvnorm = norm elif isinstance(geo, ArcGeo): geo_b = deepcopy(geo) if first: first = False prvend = geo_b.Ps + startnorm prvnorm = startnorm if geo_b.ext > 0.0: norma = offset * Point(cos(geo_b.s_ang + pi / 2), sin(geo_b.s_ang + pi / 2)) norme = Point(cos(geo_b.e_ang + pi / 2), sin(geo_b.e_ang + pi / 2)) else: norma = offset * Point(cos(geo_b.s_ang - pi / 2), sin(geo_b.s_ang - pi / 2)) norme = Point(cos(geo_b.e_ang - pi / 2), sin(geo_b.e_ang - pi / 2)) geo_b.Ps += norma if norme.x > 0: geo_b.Pe = Point( geo_b.Pe.x + offset / (sqrt(1 + (norme.y / norme.x)**2)), geo_b.Pe.y + (offset * norme.y / norme.x) / (sqrt(1 + (norme.y / norme.x)**2))) elif norme.x == 0: geo_b.Pe = Point(geo_b.Pe.x, geo_b.Pe.y) else: geo_b.Pe = Point( geo_b.Pe.x - offset / (sqrt(1 + (norme.y / norme.x)**2)), geo_b.Pe.y - (offset * norme.y / norme.x) / (sqrt(1 + (norme.y / norme.x)**2))) if prvnorm != norma: direction = prvnorm.to3D().cross_product(norma.to3D()).z swivel = ArcGeo(Ps=prvend, Pe=geo_b.Ps, r=offset, direction=direction) swivel.drag = drag_angle < abs(swivel.ext) self.append(swivel) prvend = geo_b.Pe prvnorm = offset * norme if -pi < geo_b.ext < pi: self.append( ArcGeo(Ps=geo_b.Ps, Pe=geo_b.Pe, r=sqrt(geo_b.r**2 + offset**2), direction=geo_b.ext)) else: geo_b = ArcGeo(Ps=geo_b.Ps, Pe=geo_b.Pe, r=sqrt(geo_b.r**2 + offset**2), direction=-geo_b.ext) geo_b.ext = -geo_b.ext self.append(geo_b) # TODO support different geos, or disable them in the GUI # else: # self.append(copy(geo)) if not prvnorm == startnorm: direction = prvnorm.to3D().cross_product(startnorm.to3D()).z self.append( ArcGeo(Ps=prvend, Pe=prvend - prvnorm + startnorm, r=offset, direction=direction)) self.geos.insert(0, RapidPos(self.geos.abs_el(0).Ps)) self.geos[0].make_abs_geo()
def __init__(self, Ps=Point(), tan_a=0.0, Pb=Point, tan_b=0.0, min_r=1e-6): """ Std. method to initialise the class. @param Ps: Start Point for the Biarc @param tan_a: Tangent of the Start Point @param Pb: End Point of the Biarc @param tan_b: Tangent of the End Point @param min_r: The minimum radius of a arc section. """ min_len = 1e-12 # Min Abstand f�r doppelten Punkt / Minimum clearance for double point min_alpha = 1e-4 # Winkel ab welchem Gerade angenommen wird inr rad / Angle for which it is assumed straight inr rad max_r = 5e3 # Max Radius ab welchem Gerade angenommen wird (5m) / Max radius is assumed from which line (5m) min_r = min_r # Min Radius ab welchem nichts gemacht wird / Min radius beyond which nothing is done self.Ps = Ps self.tan_a = tan_a self.Pb = Pb self.tan_b = tan_b self.l = 0.0 self.shape = None self.geos = [] self.k = 0.0 # Errechnen der Winkel, L�nge und Shape # Calculate the angle, length and shape norm_angle, self.l = self.calc_normal(self.Ps, self.Pb) alpha, beta, self.theta, self.shape = self.calc_diff_angles(norm_angle, self.tan_a, self.tan_b, min_alpha) if self.l < min_len: self.shape = "Zero" elif self.shape == "LineGeo": # Erstellen der Geometrie # Create the geometry self.geos.append(LineGeo(self.Ps, self.Pb)) else: # Berechnen der Radien, Mittelpunkte, Zwichenpunkt # Calculate the radii, midpoints Zwichenpunkt r1, r2 = self.calc_r1_r2(self.l, alpha, beta, self.theta) if abs(r1) > max_r or abs(r2) > max_r: # Erstellen der Geometrie # Create the geometry self.shape = "LineGeo" self.geos.append(LineGeo(self.Ps, self.Pb)) return # elif abs(r1) < min_r or abs(r2) < min_r: # self.shape = "Zero" # return O1, O2, k = self.calc_O1_O2_k(r1, r2, self.tan_a, self.theta) # Berechnen der Start und End- Angles f�r das drucken # Calculate the start and end angles for the print s_ang1, e_ang1 = self.calc_s_e_ang(self.Ps, O1, k) s_ang2, e_ang2 = self.calc_s_e_ang(k, O2, self.Pb) # Berechnen der Richtung und der Extend # Calculate the direction and extent dir_ang1 = (tan_a - s_ang1) % (-2 * pi) dir_ang1 -= ceil(dir_ang1 / pi) * (2 * pi) dir_ang2 = (tan_b - e_ang2) % (-2 * pi) dir_ang2 -= ceil(dir_ang2 / pi) * (2 * pi) # Erstellen der Geometrien # Create the geometries self.geos.append(ArcGeo(Ps=self.Ps, Pe=k, O=O1, r=r1, s_ang=s_ang1, e_ang=e_ang1, direction=dir_ang1)) self.geos.append(ArcGeo(Ps=k, Pe=self.Pb, O=O2, r=r2, s_ang=s_ang2, e_ang=e_ang2, direction=dir_ang2))
def make_own_cutter_compensation(self): toolwidth = self.shape.parentLayer.getToolRadius() geos = Geos([]) direction = -1 if self.shape.cut_cor == 41 else 1 if self.shape.closed: end, end_dir = self.shape.get_start_end_points(False, False) end_proj = Point(direction * end_dir.y, -direction * end_dir.x) prv_Pe = end + toolwidth * end_proj else: prv_Pe = None for geo_nr, geo in enumerate(self.shape.geos.abs_iter()): start, start_dir = geo.get_start_end_points(True, False) end, end_dir = geo.get_start_end_points(False, False) start_proj = Point(direction * start_dir.y, -direction * start_dir.x) end_proj = Point(direction * end_dir.y, -direction * end_dir.x) Ps = start + toolwidth * start_proj Pe = end + toolwidth * end_proj if Ps == Pe: continue if prv_Pe: r = geo.Ps.distance(Ps) d = (prv_Pe - geo.Ps).to3D().cross_product( (Ps - geo.Ps).to3D()).z if direction * d > 0 and prv_Pe != Ps: geos.append( ArcGeo(Ps=prv_Pe, Pe=Ps, O=geo.Ps, r=r, direction=d)) geos[-1].geo_nr = geo_nr # else: # geos.append(LineGeo(Ps=prv_Pe, Pe=Ps)) if isinstance(geo, LineGeo): geos.append(LineGeo(Ps, Pe)) geos[-1].geo_nr = geo_nr elif isinstance(geo, ArcGeo): O = geo.O r = O.distance(Ps) geos.append(ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r, direction=geo.ext)) geos[-1].geo_nr = geo_nr # TODO other geos are not supported; disable them in gui for this option # else: # geos.append(geo) prv_Pe = Pe tot_length = 0 for geo in geos.abs_iter(): tot_length += geo.length reorder_shape = False for start_geo_nr in range(len(geos)): # if shape is not closed we may only remove shapes from the start last_geo_nr = start_geo_nr if self.shape.closed else 0 geos_adj = deepcopy(geos[start_geo_nr:]) + deepcopy( geos[:last_geo_nr]) new_geos = Geos([]) i = 0 while i in range(len(geos_adj)): geo = geos_adj[i] intersections = [] for j in range(i + 1, len(geos_adj)): intersection = Intersect.get_intersection_point( geos_adj[j], geos_adj[i]) if intersection and intersection != geos_adj[i].Ps: intersections.append([j, intersection]) if len(intersections) > 0: intersection = intersections[-1] change_end_of_geo = True if i == 0 and intersection[0] >= len(geos_adj) // 2: geo.update_start_end_points(True, intersection[1]) geos_adj[intersection[0]].update_start_end_points( False, intersection[1]) if len(intersections) > 1: intersection = intersections[-2] else: change_end_of_geo = False i += 1 if change_end_of_geo: geo.update_start_end_points(False, intersection[1]) i = intersection[0] geos_adj[i].update_start_end_points( True, intersection[1]) else: i += 1 # TODO # if len(new_geos) > 0 and not new_geos[-1].Pe.eq(geo.Ps, g.config.fitting_tolerance): # break # geo is disconnected new_geos.append(geo) if new_geos[0].Ps == new_geos[-1].Pe: break new_length = 0 for geo in new_geos: new_length += geo.length if tot_length * g.config.vars.Cutter_Compensation['min_length_considered']\ <= new_length <= tot_length * g.config.vars.Cutter_Compensation['max_length_considered'] and\ (not g.config.vars.Cutter_Compensation['direction_maintained'] or not self.shape.closed or self.shape.isDirectionOfGeosCCW(new_geos) != self.shape.cw): self.append(RapidPos(new_geos[0].Ps)) for geo in new_geos: if geo.Ps != geo.Pe: self.append(geo) reorder_shape = True break if reorder_shape and self.shape.closed: # we do not reorder the original shape if it's not closed self.shape.geos = Geos( self.shape.geos[geos[start_geo_nr].geo_nr:] + self.shape.geos[:geos[start_geo_nr].geo_nr]) if len(self.geos) == 0: self.append(RapidPos(self.start))
def make_swivelknife_move(self): """ Set these variables for your tool and material @param offset: knife tip distance from tool centerline. The radius of the tool is used for this. """ offset = self.shape.parentLayer.getToolRadius() drag_angle = self.shape.drag_angle startnorm = offset*Point(1, 0) # TODO make knife direction a config setting prvend, prvnorm = Point(), Point() first = True for geo in self.shape.geos.abs_iter(): if isinstance(geo, LineGeo): geo_b = deepcopy(geo) if first: first = False prvend = geo_b.Ps + startnorm prvnorm = startnorm norm = offset * (geo_b.Pe - geo_b.Ps).unit_vector() geo_b.Ps += norm geo_b.Pe += norm if not prvnorm == norm: direction = prvnorm.to3D().cross_product(norm.to3D()).z swivel = ArcGeo(Ps=prvend, Pe=geo_b.Ps, r=offset, direction=direction) swivel.drag = drag_angle < abs(swivel.ext) self.append(swivel) self.append(geo_b) prvend = geo_b.Pe prvnorm = norm elif isinstance(geo, ArcGeo): geo_b = deepcopy(geo) if first: first = False prvend = geo_b.Ps + startnorm prvnorm = startnorm if geo_b.ext > 0.0: norma = offset*Point(cos(geo_b.s_ang+pi/2), sin(geo_b.s_ang+pi/2)) norme = Point(cos(geo_b.e_ang+pi/2), sin(geo_b.e_ang+pi/2)) else: norma = offset*Point(cos(geo_b.s_ang-pi/2), sin(geo_b.s_ang-pi/2)) norme = Point(cos(geo_b.e_ang-pi/2), sin(geo_b.e_ang-pi/2)) geo_b.Ps += norma if norme.x > 0: geo_b.Pe = Point(geo_b.Pe.x+offset/(sqrt(1+(norme.y/norme.x)**2)), geo_b.Pe.y+(offset*norme.y/norme.x)/(sqrt(1+(norme.y/norme.x)**2))) elif norme.x == 0: geo_b.Pe = Point(geo_b.Pe.x, geo_b.Pe.y) else: geo_b.Pe = Point(geo_b.Pe.x-offset/(sqrt(1+(norme.y/norme.x)**2)), geo_b.Pe.y-(offset*norme.y/norme.x)/(sqrt(1+(norme.y/norme.x)**2))) if prvnorm != norma: direction = prvnorm.to3D().cross_product(norma.to3D()).z swivel = ArcGeo(Ps=prvend, Pe=geo_b.Ps, r=offset, direction=direction) swivel.drag = drag_angle < abs(swivel.ext) self.append(swivel) prvend = geo_b.Pe prvnorm = offset*norme if -pi < geo_b.ext < pi: self.append(ArcGeo(Ps=geo_b.Ps, Pe=geo_b.Pe, r=sqrt(geo_b.r**2+offset**2), direction=geo_b.ext)) else: geo_b = ArcGeo(Ps=geo_b.Ps, Pe=geo_b.Pe, r=sqrt(geo_b.r**2+offset**2), direction=-geo_b.ext) geo_b.ext = -geo_b.ext self.append(geo_b) # TODO support different geos, or disable them in the GUI # else: # self.append(copy(geo)) if not prvnorm == startnorm: direction = prvnorm.to3D().cross_product(startnorm.to3D()).z self.append(ArcGeo(Ps=prvend, Pe=prvend-prvnorm+startnorm, r=offset, direction=direction)) self.geos.insert(0, RapidPos(self.geos.abs_el(0).Ps)) self.geos[0].make_abs_geo()