Пример #1
0
def arrow(x0,y0,x1,y1,color=0,ang=45.0,height=6,width=1.5,lc=None):
    """Draw an arrow.

    Description:

      Draw an arrow from (x0,y0) to (x1,y1) in the current coordinate system.

    Inputs:

      x0, y0 -- The beginning point.
      x1, y1 -- Then ending point.
      color -- The color of the arrowhead.  Number represents an index
               in the current palette or a negative number or a spelled
               out basic color.
      lc -- The color of the line (same as color by default).
      ang -- The angle of the arrowhead.
      height -- The height of the arrowhead in points.
      width -- The width of the arrow line in points.
    """
    if lc is None:
        lc = color
    if type(lc) is types.StringType:
        lc = _colornum[lc]
    if type(color) is types.StringType:
        color = _colornum[color]
    vp = gist.viewport()
    plotlims = gist.limits()
    gist.limits(plotlims)
    conv_factorx = (vp[1]-vp[0]) / (plotlims[1]-plotlims[0])
    conv_factory = (vp[3]-vp[2]) / (plotlims[3]-plotlims[2])
    ang = ang*pi/180
    height = height*points
    hypot = height / cos(ang)
    difx = (x1 - x0) * conv_factorx
    dify = (y1 - y0) * conv_factory
    theta = arctan2(dify,difx) + pi
    tha = theta + ang
    thb = theta - ang
    x1a = x1 + hypot*cos(tha) / conv_factorx
    x1b = x1 + hypot*cos(thb) / conv_factorx
    y1a = y1 + hypot*sin(tha) / conv_factory
    y1b = y1 + hypot*sin(thb) / conv_factory
    gist.pldj([x0],[y0],[x1],[y1],color=lc,width=width)
    gist.plfp(array([color],'B'),[y1,y1a,y1b],[x1,x1a,x1b],[3])
    return
Пример #2
0
    def __init__(self, numPoints, k):
        """numPoints: number of approximation points; k: number of basis functions [2,...,numPoints]"""
        self.numPoints = numPoints
        self.k = k
##        assert k > 1, "Error TrigonomerticBasis: k <= 1"
        assert k <= numPoints, "Error TrigonomerticBasis: k > numPoints"
        # evaluate trigonometric basis functions on the given number of points from [-pi,pi]
        self.x = Numeric.arange(-1*math.pi, math.pi+0.0000001, 2*math.pi/(numPoints-1))
        self.y = Numeric.ones((k, numPoints), Numeric.Float)
        for kk in range(1, k, 2):
##            print "kk, cos %ix" % ((kk+1)/2.)
            self.y[kk] = MLab.cos(self.x*(kk+1)/2) 
        for kk in range(2, k, 2):
##            print "kk, sin %ix" % (kk/2.)
            self.y[kk] = MLab.sin(self.x*kk/2)
        # approx. matrix
        self.Ainv = LinearAlgebra.inverse(Numeric.matrixmultiply(self.y, Numeric.transpose(self.y)))
        self.yyTinvy = Numeric.matrixmultiply(LinearAlgebra.inverse(Numeric.matrixmultiply(self.y, Numeric.transpose(self.y))), self.y)
Пример #3
0
 def __init__(self, numPoints, k):
     """numPoints: number of approximation points; k: number of basis functions [2,...,numPoints]"""
     self.numPoints = numPoints
     self.k = k
     ##        assert k > 1, "Error TrigonomerticBasis: k <= 1"
     assert k <= numPoints, "Error TrigonomerticBasis: k > numPoints"
     # evaluate trigonometric basis functions on the given number of points from [-pi,pi]
     self.x = Numeric.arange(-1 * math.pi, math.pi + 0.0000001,
                             2 * math.pi / (numPoints - 1))
     self.y = Numeric.ones((k, numPoints), Numeric.Float)
     for kk in range(1, k, 2):
         ##            print "kk, cos %ix" % ((kk+1)/2.)
         self.y[kk] = MLab.cos(self.x * (kk + 1) / 2)
     for kk in range(2, k, 2):
         ##            print "kk, sin %ix" % (kk/2.)
         self.y[kk] = MLab.sin(self.x * kk / 2)
     # approx. matrix
     self.Ainv = LinearAlgebra.inverse(
         Numeric.matrixmultiply(self.y, Numeric.transpose(self.y)))
     self.yyTinvy = Numeric.matrixmultiply(
         LinearAlgebra.inverse(
             Numeric.matrixmultiply(self.y, Numeric.transpose(self.y))),
         self.y)