当前位置: 首页>>代码示例>>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;未经允许,请勿转载。