def _draw_equilibrium(self): width = 3 orig_coords = [p.get_xy() for p in self.points] items = [] for sig in (-1, 1): coords = geometry.find_parallel_polyline(orig_coords, sig * width) if sig == -1: x1, y1 = coords[1] x2, y2 = coords[0] coords[0] = geometry.elongate_line( x1, y1, x2, y2, -8) # shorten the line - looks better else: x1, y1 = coords[-2] x2, y2 = coords[-1] coords[-1] = geometry.elongate_line( x1, y1, x2, y2, -8) # shorten the line - looks better # the line ps = tuple(j for i in coords for j in i) item1 = self.paper.create_line(ps, tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color) items.append(item1) # the pin cs = single_sided_arrow_head(x1, y1, x2, y2, 8, 10, 3, self.line_width) items.append( self.paper.create_polygon(cs, fill=self.line_color, outline=self.line_color, width=1, tags="arrow_no_focus", joinstyle="miter")) return items
def _draw_electron(self): coords = [p.get_xy() for p in self.points] pins = [] if self.pin in (2, 3): x1, y1 = coords[1] x2, y2 = coords[0] pins.append((x1, y1, x2, y2)) coords[0] = geometry.elongate_line( x1, y1, x2, y2, -8) # shorten the line - looks better if self.pin in (1, 3): x1, y1 = coords[-2] x2, y2 = coords[-1] pins.append((x1, y1, x2, y2)) coords[-1] = geometry.elongate_line( x1, y1, x2, y2, -8) # shorten the line - looks better ps = tuple(j for i in coords for j in i) item1 = self.paper.create_line(ps, tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color) items = [item1] for x1, y1, x2, y2 in pins: coords = single_sided_arrow_head(x1, y1, x2, y2, 8, 10, 4, self.line_width) items.append( self.paper.create_polygon(coords, fill=self.line_color, outline=self.line_color, width=1, tags="arrow_no_focus", joinstyle="miter")) return items
def double_sided_arrow_head (x1,y1,x2,y2,a,b,c): '''last two points of arrow 1->2 a,b,c like tkinter a = leght from point 2 where the head touches the line (out point A) b = total lenght of the head (defines also help point P on the line) c = width Point B will be the outer Point of the head rl = "r" the head is on the right , = "l" left''' xa,ya = x2,y2 xp,yp = geometry.elongate_line (x1,y1,x2,y2,-b) xb,yb = geometry.point_at_distance_from_line (x1,y1,xp,yp,c) xd,yd = geometry.point_at_distance_from_line (x1,y1,xp,yp,-c) xc,yc = geometry.elongate_line (x1,y1,x2,y2,-a) return xa,ya, xb,yb, xc,yc, xd,yd
def _draw_equilibrium2(self): width = 3 orig_coords = [p.get_xy() for p in self.points] items = [] for sig in (-1, 1): coords = geometry.find_parallel_polyline(orig_coords, sig * width) if not self.spline: # if its not a spline, we can draw it all in one go if sig == -1: x1, y1 = coords[1] x2, y2 = coords[0] xp, yp = geometry.elongate_line(x1, y1, x2, y2, -8) xp, yp = geometry.point_at_distance_from_line( x1, y1, xp, yp, 5) coords.insert(0, (xp, yp)) else: x1, y1 = coords[-2] x2, y2 = coords[-1] xp, yp = geometry.elongate_line(x1, y1, x2, y2, -8) xp, yp = geometry.point_at_distance_from_line( x1, y1, xp, yp, 5) coords.append((xp, yp)) else: # splines must have a sharp point at the end - the must have a separate head if sig == -1: x1, y1 = coords[1] x2, y2 = coords[0] else: x1, y1 = coords[-2] x2, y2 = coords[-1] xp, yp = geometry.elongate_line(x1, y1, x2, y2, -8) xp, yp = geometry.point_at_distance_from_line( x1, y1, xp, yp, 5) items.append( self.paper.create_line((x2, y2, xp, yp), tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color, joinstyle="miter")) # the line (with optional pin) ps = tuple(j for i in coords for j in i) item1 = self.paper.create_line(ps, tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color, joinstyle="miter") items.append(item1) return items
def single_sided_arrow_head (x1,y1,x2,y2,a,b,c,lw): '''last two points of arrow 1->2 a,b,c like tkinter a = leght from point 2 where the head touches the line (out point A) b = total lenght of the head (defines also help point P on the line) c = width Point B will be the outer Point of the head rl = "r" the head is on the right , = "l" left, lw is the line_width of the line the arrow will be attached to''' xa,ya = geometry.elongate_line (x1,y1,x2,y2,-a) xa,ya = geometry.point_at_distance_from_line (x1,y1,xa,ya,-misc.signum(c)*(lw-1.0)/2.0) xp,yp = geometry.elongate_line (x1,y1,x2,y2,-b) xb,yb = geometry.point_at_distance_from_line (x1,y1,xp,yp,c) xc,yc = geometry.point_at_distance_from_line (x1,y1,x2,y2,-misc.signum(c)*(lw-1.0)/2.0) return xa,ya, xc,yc, xb,yb
def _draw_equilibrium2( self): width = 3 orig_coords = [p.get_xy() for p in self.points] items = [] for sig in (-1,1): coords = geometry.find_parallel_polyline( orig_coords, sig*width) if not self.spline: # if its not a spline, we can draw it all in one go if sig == -1: x1, y1 = coords[1] x2, y2 = coords[0] xp, yp = geometry.elongate_line( x1,y1,x2,y2,-8) xp, yp = geometry.point_at_distance_from_line( x1,y1,xp,yp,5) coords.insert(0,(xp,yp)) else: x1, y1 = coords[-2] x2, y2 = coords[-1] xp, yp = geometry.elongate_line( x1,y1,x2,y2,-8) xp, yp = geometry.point_at_distance_from_line( x1,y1,xp,yp,5) coords.append((xp,yp)) else: # splines must have a sharp point at the end - the must have a separate head if sig == -1: x1, y1 = coords[1] x2, y2 = coords[0] else: x1, y1 = coords[-2] x2, y2 = coords[-1] xp, yp = geometry.elongate_line( x1,y1,x2,y2,-8) xp, yp = geometry.point_at_distance_from_line( x1,y1,xp,yp,5) items.append( self.paper.create_line( (x2,y2,xp,yp), tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color, joinstyle="miter")) # the line (with optional pin) ps = reduce( operator.add, coords) item1 = self.paper.create_line( ps, tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color, joinstyle="miter") items.append( item1) return items
def retro_arrow_head (x1,y1,x2,y2,length,width,d): """arrow head at 2 # length # |---| _ # C\ | # \ | width # A----------------B\-P | # 1 d | __R___\|2 - # /| # D----------------E/-Q # / # F/ # P,Q,R are not drawn """ w_ratio = 1.0*d / width dl = w_ratio * length xh ,yh = geometry.elongate_line( x1,y1,x2,y2,dl) xr, yr = geometry.elongate_line( x1,y1,x2,y2,dl-length) xc, yc = geometry.point_at_distance_from_line (x1,y1,xr,yr,width) xf, yf = geometry.point_at_distance_from_line (x1,y1,xr,yr,-width) return (xc,yc, xh,yh, xf,yf)
def _draw_equilibrium( self): width = 3 orig_coords = [p.get_xy() for p in self.points] items = [] for sig in (-1,1): coords = geometry.find_parallel_polyline( orig_coords, sig*width) if sig == -1: x1, y1 = coords[1] x2, y2 = coords[0] coords[0] = geometry.elongate_line( x1,y1,x2,y2,-8) # shorten the line - looks better else: x1, y1 = coords[-2] x2, y2 = coords[-1] coords[-1] = geometry.elongate_line( x1,y1,x2,y2,-8) # shorten the line - looks better # the line ps = reduce( operator.add, coords) item1 = self.paper.create_line( ps, tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color) items.append( item1) # the pin cs = single_sided_arrow_head(x1, y1, x2, y2, 8, 10, 3, self.line_width) items.append( self.paper.create_polygon( cs, fill=self.line_color, outline=self.line_color, width=1, tags="arrow_no_focus", joinstyle="miter")) return items
def _draw_electron( self): coords = [p.get_xy() for p in self.points] pins = [] if self.pin in (2,3): x1, y1 = coords[1] x2, y2 = coords[0] pins.append( (x1,y1,x2,y2)) coords[0] = geometry.elongate_line( x1,y1,x2,y2,-8) # shorten the line - looks better if self.pin in (1,3): x1, y1 = coords[-2] x2, y2 = coords[-1] pins.append( (x1,y1,x2,y2)) coords[-1] = geometry.elongate_line( x1,y1,x2,y2,-8) # shorten the line - looks better ps = reduce( operator.add, coords) item1 = self.paper.create_line( ps, tags='arrow', width=self.line_width, smooth=self.spline, fill=self.line_color) items = [item1] for x1,y1,x2,y2 in pins: coords = single_sided_arrow_head(x1, y1, x2, y2, 8, 10, 4, self.line_width) items.append( self.paper.create_polygon( coords, fill=self.line_color, outline=self.line_color, width=1, tags="arrow_no_focus", joinstyle="miter")) return items