當前位置: 首頁>>代碼示例>>Python>>正文


Python Vector類代碼示例

本文整理匯總了Python中Vector的典型用法代碼示例。如果您正苦於以下問題:Python Vector類的具體用法?Python Vector怎麽用?Python Vector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Vector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

class Obstacle:
    def __init__(self,x,y,vx,vy):
        self.pos = Vector(x,y)
        self.vel = Vector(vx,vy)
        self.acc = Vector(0,1)
        self.c = color(random(60),random(80),random(255))
        self.radius = 10
        self.elasticity = 0.9
        self.dead = False
        self.life = 0
        self.inc = 1
    
    def isDead(self):
        return self.dead
    
    def getX(self):
        return self.pos.getX()
    
    def getY(self):
        return self.pos.getY()
    
    def getR(self):
        return self.radius
    
    def render(self):
        fill(self.c)
        wall = loadImage("Wall.png")       
        image(wall, self.pos.getX(),self.pos.getY())    
    def update(self):
        #Lifetime
        self.life += self.inc
        if self.life > 1000:
            self.dead = True
開發者ID:pablofernandezcom,項目名稱:minimario,代碼行數:33,代碼來源:Obstacle.py

示例2: Specular

def Specular(aNormal,aTrianglePoint):
  eyeVector = [cameraX - aTrianglePoint[X],
               cameraY - aTrianglePoint[Y],
               cameraZ - aTrianglePoint[Z],
               1.0     - aTrianglePoint[3]]

  eyeVector = Vector.normalize(eyeVector)
 
  lightVec = [lightPoint[X] - aTrianglePoint[X],
              lightPoint[Y] - aTrianglePoint[Y],
              lightPoint[Z] - aTrianglePoint[Z],
              lightPoint[W] - aTrianglePoint[W]]
  
  lightVec = Vector.normalize(lightVec)

  #caculate the half vector
  H = [lightVec[X] + eyeVector[X],
       lightVec[Y] + eyeVector[Y],
       lightVec[Z] + eyeVector[Z],
       lightVec[W] + eyeVector[W]]

  #now normalize and dot the half with the normal vec,
  #use the shininess constant defined in IncludesAndConstants.py
  H = Vector.normalize(H)
  d = Vector.dotProduct(aNormal,H)
  return math.pow(max(d,0),shininess)
開發者ID:LloydGhettoWolf,項目名稱:Python-Renderer,代碼行數:26,代碼來源:Lighting.py

示例3: nextTriangle

def nextTriangle(A,B,C):
  [B,C,A] = Vector.sort([A,B,C])
  D = B + C - A
  E = 3* (B+C)/ 2- 2*A
  F = (3* (B+C)- 2*A)/4
  G = (2* A+ B+ C)/4
  if F.cost() < G.cost():
    X = Vector(F)
  else:
    X = Vector(G)
  #case 1: vertex A moves to D or E
  if D.cost() < A.cost() and E.cost() < A.cost():
    A.equals(E)
  elif D.cost() < A.cost():
    A.equals(D)
  #case 2: vertex A moves to F or G
  elif X.cost() < A.cost():
    A.equals(X)
  #case 3: vertex A moves to H and vertex C moves to I
  else:
    H = (A + B)/2
    I = (B + C)/2
    A.equals(H)
    C.equals(I)
  return A,B,C
開發者ID:changarno,項目名稱:tjhsst1314,代碼行數:25,代碼來源:NelderMead-.py

示例4: resetControl

 def resetControl(self):
     self.switch = 0
     self.error = Vector(0,0)
     self.errorPrev = Vector(0,0)        
     self.derror = Vector(0,0)        
     self.errorSum = Vector(0,0)
     self.program = None
開發者ID:ricsirke,項目名稱:Drone-Simulation,代碼行數:7,代碼來源:Control.py

示例5: oscillateCurve

def oscillateCurve( curve, start=0.0, end=1.0, freq=1.0, ease=0.5, strength=1.0 ):
    """ Oscillates a given curve by moving each vertex in an alternating
        direction based on the normal.  This process takes place over the
        range defined by "start" and "end" as percentages of arc length.
        Oscillation eases to full strength as determined by the "ease" and
        "strength" arguments. """
    if(ease > (end-start)*0.5):
        ease = (end-start)*0.5
    if(start < end):
        CVs = mc.getAttr( curve+".cv[*]" )
        newCVs = findCVsInRange(curve, start, end)
        for (I,U,L) in newCVs:
            interp = (L-start)/(end-start)
            osc = sin(freq*interp)
            scale = pulse(start+ease, end, ease, L)  # ease must be between 0 and 0.5
## Don't use Maya's normalized normal -- it flip flops with curvature so it's not good for oscillating offset
#            normal = Vector(mc.pointOnCurve(curve, parameter=cv[1], normalizedNormal=True))
#            if(normal.mag() == 0.0):
#                print "Getting normal from up x tangent"
            normal = Vector(0,1,0)**Vector(mc.pointOnCurve(curve, parameter=U, tangent=True))
            normal = normal.norm()
            pos = Vector(CVs[I])
            pos = pos+normal*scale*strength*osc
            CVs[I] = pos.asTuple()

    for i,cv in enumerate(CVs):
        mc.setAttr(curve+".cv[%d]"%i, cv[0], cv[1], cv[2])

    return curve
開發者ID:jeisenma,項目名稱:traceSelectionInMaya,代碼行數:29,代碼來源:curveUtil.py

示例6: reinit

	def reinit(self):
		self.pos = Vector(Conf.TURTLE.INIT_POS)
		self.heading = Vector(Conf.TURTLE.INIT_HEADING)
		self.color = Vector(colorsys.rgb_to_hls(Conf.TURTLE.INIT_COLOR[0], Conf.TURTLE.INIT_COLOR[1], Conf.TURTLE.INIT_COLOR[2]))
		self.vertexBuffer = []
		self.vertexBufferChanged = False
		self.vertexBufferLength = 0
		self.vertexPositions = vbo.VBO(np.array(self.vertexBuffer, dtype=np.float32))
		self.vertexPositions.bind()
開發者ID:Hiestaa,項目名稱:3D-Lsystem,代碼行數:9,代碼來源:Turtle.py

示例7: __init__

 def __init__(self,x,y,vx,vy):
     self.pos = Vector(x,y)
     self.vel = Vector(vx,vy)
     self.acc = Vector(0,1)
     self.c = color(random(60),random(80),random(255))
     self.radius = 10
     self.elasticity = 0.8
     self.dead = False
     self.life = 0
     self.inc = 1
開發者ID:pablofernandezcom,項目名稱:minimario,代碼行數:10,代碼來源:Ball.py

示例8: execute

def execute(*args):
    """Test all derived functions for proper operation
    
    """
    
    import Vector
    reload(Vector)
    Vector.test()
    
    import Add
    reload(Add)
    Add.test()
    
    import Multiply
    reload(Multiply)
    Multiply.test()
    
    import Divide
    reload(Divide)
    Divide.test()
    
    import Difference
    reload(Difference)
    Difference.test()
    
    import Poly
    reload(Poly)
    Poly.test()
    
    import Average
    reload(Average)
    Average.test()
    
    import LinTrans
    reload(LinTrans)
    LinTrans.test()
    
    import Test
    reload(Test)
    Test.test()
    
    import Rotate
    reload(Rotate)
    Rotate.test()
    
    import Magnitude
    reload(Magnitude)
    Magnitude.test()
    
    import Cape
    reload(Cape)
    Cape.test()
    
    print "-"*60
    print "Function Test Complete"
開發者ID:KeithLatteri,項目名稱:awips2,代碼行數:55,代碼來源:FunctionTest.py

示例9: __init__

 def __init__(self, dt):
     self.dt = dt
     self.rotorspeed = Vector(0.0, 0.0)
     self.pos = Vector(0,0)
     self.speed = Vector(0.0,0.0)
     self.acc = Vector(0.0, 0.0)
     
     self.posPrev = Vector(0.0, 0.0)
     self.speedPrev = Vector(0.0, 0.0)
     
     self.control = None
開發者ID:ricsirke,項目名稱:Drone-Simulation,代碼行數:11,代碼來源:Drone.py

示例10: Diffuse

def Diffuse(aNormal,aTrianglePoint):
  lightVec = [ lightPoint[X] - aTrianglePoint[X],
               lightPoint[Y] - aTrianglePoint[Y],
               lightPoint[Z] - aTrianglePoint[Z],
               lightPoint[W] - aTrianglePoint[W]]

  lightVec = Vector.normalize(lightVec)
  #print(lightVec[X],lightVec[Y],lightVec[Z])
  #print(Vector.length(lightVec))
  aNormal = Vector.normalize(aNormal)

  return max(Vector.dotProduct(lightVec,aNormal),0)  
開發者ID:LloydGhettoWolf,項目名稱:Python-Renderer,代碼行數:12,代碼來源:Lighting.py

示例11: getMinMaxItems

	def getMinMaxItems(self):
		self.itemMAX = Vector(self.iteminfo[0][0])
		self.itemMIN = Vector(self.iteminfo[0][0])
		self.itemMEAN = Vector(self.iteminfo[0][0])
		for idx in range(1, len(self.iteminfo)):
			self.itemMAX.upper( self.iteminfo[idx][0] )
			self.itemMIN.lower( self.iteminfo[idx][0] )
			self.itemMEAN += self.iteminfo[idx][0]
			#print self.iteminfo[idx][0].str()
			#print self.itemMAX.str()
			#print self.itemMIN.str()
		self.itemMEAN /= len(self.iteminfo)
開發者ID:handol,項目名稱:python_study,代碼行數:12,代碼來源:Clustering.py

示例12: createDendrites

    def createDendrites(self):
        angle           = 360.0/self.branches
        startDist       = 0.95 * self.somaSize
        endDist         = startDist + self.stepDist
        halfThickness   = self.dendriteThickness/2.0
        
        a = 0.0
        while a<360.0:
            
            # Define the points that the dendrite would follow if it were a line (i.e. no thickness)
            initialResources = self.maxRadius 
            p1, p2 = Vector(), Vector()
            p1.x = m.cos(m.radians(a)) * startDist + self.center.x
            p1.y = m.sin(m.radians(a)) * startDist + self.center.y
            p2.x = m.cos(m.radians(a)) * endDist + self.center.x
            p2.y = m.sin(m.radians(a)) * endDist + self.center.y
            remainingResources = initialResources - p1.distance(p2)

            # Find the first and last vertex of the quad (moving perpendicular from p1 to create thickness)
            t = p1 - self.center
            leftPerp    = t.leftXYPerpendicular().normalize()
            rightPerp   = t.rightXYPerpendicular().normalize()
            v1 = leftPerp * halfThickness + p1
            v4 = rightPerp * halfThickness + p1

            # Find the second and third vertex of the quad (moving perpendicular from p2 to create thickness)
            t = p2 - p1
            leftPerp    = t.leftXYPerpendicular().normalize()
            rightPerp   = t.rightXYPerpendicular().normalize()
            v2 = leftPerp * halfThickness + p2
            v3 = rightPerp * halfThickness + p2

            # Find the vertex index of the newly added vertices
            startVertexNumber = len(self.verts)
            v1Number = startVertexNumber
            v2Number = startVertexNumber + 1
            v3Number = startVertexNumber + 2
            v4Number = startVertexNumber + 3

            # Add the vertices
            self.verts = self.verts + [v1.toList(), v2.toList(), v3.toList(), v4.toList()]

            # Add a properly ordered face
            face = self.createOrderedQuad(v1, v2, v3, v4, v1Number, v2Number, v3Number, v4Number)
            self.faces.append(face)

            # Store some information about the current dendrite branch
            self.dendrites.append([[a,initialResources,p1,[v1,v1Number],[v4,v4Number]],
                                   [a,remainingResources,p2,[v2,v2Number],[v3,v3Number]]])
            self.lineSegments.append([p1, (p1+p2)/2.0, p2])
            self.updateRadius(v1, v2, v3, v4)
            a += angle
開發者ID:mikewesthad,項目名稱:LitWithinBlender,代碼行數:52,代碼來源:Neuron.py

示例13: runRandomSearch

def runRandomSearch():
  startTime = clock()
  vector = Vector(random()*DOMAIN_LIMIT,random()*DOMAIN_LIMIT)
  minc= vector.cost()
  while(clock() - startTime < MAX_RUN_TIME):
    global PROBE_COUNT1
    PROBE_COUNT1+=1
    vector = Vector(random()*DOMAIN_LIMIT,random()*DOMAIN_LIMIT)
    if(vector.cost() < minc):
      minc = vector.cost()
  print('2. Random Probing used', PROBE_COUNT1, 'probes.')
  print('Vector =', vector, 'Cost =', round(minc,5))
  print('---Search time =', round(clock() - startTime, 2), 'seconds\n')
開發者ID:changarno,項目名稱:tjhsst1314,代碼行數:13,代碼來源:NelderMead.py

示例14: TestForCull

def TestForCull(aTriangle):
  camVector = [IncludesAndConstants.lookPointX - IncludesAndConstants.cameraX,
               IncludesAndConstants.lookPointY - IncludesAndConstants.cameraY,
               IncludesAndConstants.lookPointZ - IncludesAndConstants.cameraZ,0]

  camVector = Vector.normalize(camVector)

  normal = [aTriangle.normal[X],aTriangle.normal[Y],aTriangle.normal[Z],0]
  normal = Vector.normalize(normal)

  if Vector.dotProduct(camVector,normal) <= 0.0:
    return True
  else:
    return False
開發者ID:LloydGhettoWolf,項目名稱:Python-Renderer,代碼行數:14,代碼來源:Triangle.py

示例15: testAssignmentOperators

def testAssignmentOperators() :
   V = Vector([1.0, 2.0, 3.0])
   print V.size()
   V.show()
   W = V
   W.show()
   for k in range(V.size()) :
      print V[k]
   for k in range(V.size()) :
      V[k] = 0.0
   V.show()
開發者ID:worldnamer,項目名稱:GeometryEngine,代碼行數:11,代碼來源:testVector.py


注:本文中的Vector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。