class Arrow(Polygon): """ An arrow patch """ def __init__( self, x, y, dx, dy, width=1.0, arrowstyle='solid', **kwargs ): """Draws an arrow, starting at (x,y), direction and length given by (dx,dy) the width of the arrow is scaled by width. arrowstyle may be 'solid' or 'barbed' """ L = math.hypot(dx,dy) or 1 # account for div by zero tL = L*0.9 #~ if width > 5*L: #~ width = tL = width/5 #~ elif width > L: if width > L: width = tL = L v = tL-width w = tL-width*0.3 arrow = {'barbed': array([[0.0, 0.1], [0.0, -0.1], [w, -0.1], [v, -0.7], [tL, 0.0], [v, 0.7], [w, 0.1]]), 'solid': array([[-width*0.05, 0.1], [-width*0.05, -0.1], [v, -0.1], [v, -0.5], [tL, 0.0], [v, 0.5], [v, 0.1]]) }[arrowstyle] arrow[:,1] *= width cx = float(dx)/L sx = float(dy)/L M = array( [ [ cx, sx],[ -sx, cx ] ] ) verts = matrixmultiply( arrow, M )+ [x,y] Polygon.__init__( self, [ tuple(t) for t in verts ], **kwargs )