本文整理汇总了Python中Vector.Vector类的典型用法代码示例。如果您正苦于以下问题:Python Vector类的具体用法?Python Vector怎么用?Python Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lanczos
def lanczos(A):
k = len(A)
b = Vector.rand(n=k)
q = [Vector.new(n=k) for i in range(2)]
q[1] = b / abs(b)
b = [0]
a = [0]
for i in range(1, int(2 * sqrt(k))):
z = Vector((A * q[i]).transpose()[0])
a.append(float(Matrix([q[i]]) * z))
z = z - q[i] * a[i] - q[i-1] * b[i-1]
for j in q:
z -= j * (z * j)
for j in q:
z -= j * (z * j)
b.append(abs(z))
if b[i] == 0:
break
q.append(z / b[i])
Q = Matrix(q[-k-1:-1]).transpose()
T = Q.transpose() * A * Q
return (Q, T, )
示例2: testInsertAtEnd
def testInsertAtEnd(self):
self.bigVec.insert(BIG_VEC_SIZE, "a")
vec = Vector()
for i in range(BIG_VEC_SIZE):
vec.append(i)
vec.append("a")
self.assertEqual(self.bigVec, vec)
示例3: __init__
def __init__(self, world, name, image, text):
"""Base class used to construct a game entity.
Returns new GameEntity object
with the specified variables world, name,image, text, location, destination, speed, brain and id, this is a super
class and should ideally be used via inheritance
world: holds a world object. For game entities this should ideally be the
world game
name: holds the name of the particular entity being constructed e.g. zombie
image: holds the location of the image that will be used as the main image
for whatever GameEntity is constructed. This image holder will also be used to
store the image as a result of rotation for display
start_image: holds the location of the image that will be used as the main image
for whatever GameEntity is constructed. This one however will not be altered but
used as a reference to reset the rotational image when a new rotation is required.
text: holds the text that will be displayed in a textual entity; for example
the TextBox Entity
location: holds a default Vector of (0,0) that will be altered to set the location
of the enity that is created
destination: holds a default Vector of (0,0) that will be altered to set the destination
location of the entity
heading: holds a default Vector of (0,0) that will be altered to set the heading; vector
between two points with no size. Can be seen as the direction
last_heading: holds a default Vector of (0,0), this heading will typically be used
to remember the last heading that was used for rotating an entity image, so that rotation
does not get caught in an infinite loop
speed: holds a number variable default 0. that will be altered to set the speed
of the entity that is created
brain: holds a StateManager object that is used to manage the states that the
entity object will use
id: holds the numerial id for the entity object that is being created
"""
self.world = world
self.name = name
self.image = image
self.start_image = image
self.text = text
self.location = Vector(0,0)
self.destination = Vector(0,0)
self.heading = Vector(0,0)
self.last_heading = Vector(0,0)
self.speed = 0.
self.brain = StateManager()
self.id = 0
示例4: __init__
def __init__(self, coords=(0, 0), speed=(0, 0)):
self.coords = Vector(coords)
self.speed = Vector(speed)
self.color = (250, 0, 0)
self.acsel = Vector((0, 0))
self.status = MOVE
self.angle_speed = 0.1
示例5: resolve
def resolve(self):
"""
Return combined result of all steering behaviours.
"""
acc=Vector(0,0)
#if type(self.player.state) == Player.RxAttack:
# pdb.set_trace()
if self._avoid_defenders_on:
acc += self.avoid_defenders() * self.w_avoid_defenders
if self._seek_on:
acc += self.seek() * self.w_seek
if self._seek_end_zone_on:
acc += self.seek_end_zone() * self.w_seek_end_zone
if self._avoid_walls_on:
acc += self.avoid_walls() * self.w_avoid_walls
if self._pursue_on:
acc += self.pursue() * self.w_pursue
if self._block_on:
acc += self.block() * self.w_block
if self._avoid_friends_on:
acc += self.avoid_friends() * self.w_avoid_friends
if self._zone_defend_on:
acc += self.zone_defend() * self.w_zone_defend
if self._guard_on:
acc += self.guard() * self.w_guard
if self._stay_in_range_on:
acc += self.stay_in_range() * self.w_stay_in_range
if self._avoid_end_zone_on:
acc += self.avoid_end_zone() * self.w_avoid_end_zone
if self._arrive_at_speed_on:
acc += self.arrive_at_speed() * self.w_arrive_at_speed
return acc.truncate(self.player.top_acc)
示例6: testRemoveWithDuplicates
def testRemoveWithDuplicates(self):
vec = Vector()
vec.append("a")
vec.append("b")
vec.append("c")
self.duplicatesVec.remove("b")
self.assertEquals(vec, self.duplicatesVec)
示例7: testRemoveAtEnd
def testRemoveAtEnd(self):
vec = Vector()
for i in range(BIG_VEC_SIZE-1):
vec.append(i)
self.bigVec.remove(BIG_VEC_SIZE-1)
self.assertEqual(vec, self.bigVec)
示例8: __init__
def __init__(self, **argd):
"""x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
super(OpenGLComponent, self).__init__()
# get transformation data and convert to vectors
self.size = Vector( *argd.get("size", (0,0,0)) )
self.position = Vector( *argd.get("position", (0,0,0)) )
self.rotation = Vector( *argd.get("rotation", (0.0,0.0,0.0)) )
self.scaling = Vector( *argd.get("scaling", (1,1,1) ) )
# for detection of changes
self.oldrot = Vector()
self.oldpos = Vector()
self.oldscaling = Vector()
self.transform = Transform()
# name (mostly for debugging)
self.name = argd.get("name", "nameless")
# create clock
self.clock = pygame.time.Clock()
self.frametime = 0.0
# get display service
displayservice = OpenGLDisplay.getDisplayService()
# link display_signal to displayservice
self.link((self,"display_signal"), displayservice)
示例9: testInsertAtStartNegative
def testInsertAtStartNegative(self):
self.bigVec.insert(-BIG_VEC_SIZE, "a")
vec = Vector()
vec.append("a")
for i in range(BIG_VEC_SIZE):
vec.append(i)
self.assertEqual(self.bigVec, vec)
示例10: volume
def volume(self):
ps = Vector(self.p,self.s)
qs = Vector(self.q,self.s)
rs = Vector(self.r,self.s)
return ps * (qs.cross(rs))/6.0
示例11: testExtendByEmpty
def testExtendByEmpty(self):
vec = Vector()
for i in range(BIG_VEC_SIZE):
vec.append(i)
self.bigVec.extend(Vector())
self.assertEqual(self.bigVec, vec)
self.assertEqual(self.bigVec, self.cleanBigVec)
示例12: __init__
def __init__(self, **argd):
"""x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
super(Container, self).__init__()
# get transformation data and convert to vectors
self.position = Vector( *argd.get("position", (0,0,0)) )
self.rotation = Vector( *argd.get("rotation", (0.0,0.0,0.0)) )
self.scaling = Vector( *argd.get("scaling", (1,1,1) ) )
# for detection of changes
self.oldrot = Vector()
self.oldpos = Vector()
self.oldscaling = Vector()
# inital apply trasformations
self.transform = Transform()
self.components = []
self.rel_positions = {}
self.rel_rotations = {}
self.rel_scalings = {}
self.poscomms = {}
self.rotcomms = {}
self.scacomms = {}
contents = argd.get("contents", None)
if contents is not None:
for (comp, params) in contents.items():
self.addElement(comp, **params)
示例13: collide
def collide(self, p1, p2):
"""Collission detection and handling method"""
distance = Vector.distance_between(p1.pos, p2.pos)
if distance < (p1.size + p2.size):
angle = Vector.angle_between(p1.pos, p2.pos) + 0.5 * math.pi
total_mass = p1.mass + p2.mass
p1.direction = Vector(p1.direction.length * (p1.mass - p2.mass) / total_mass, p1.direction.angle) \
+ Vector(2 * p2.direction.length * p2.mass / total_mass, angle)
p2.direction = Vector(p2.direction.length * (p2.mass - p1.mass) / total_mass, p2.direction.angle) \
+ Vector(2 * p1.direction.length * p1.mass / total_mass, angle)
p1.direction.length *= self.elasticity
p2.direction.length *= self.elasticity
tangent = Vector.angle_between(p1.pos, p2.pos)
# bounce on tangent
#p1.direction.bounce(2 * tangent)
#p2.direction.bounce(2 * tangent)
# change speed
#(p1.direction.length, p2.direction.length) = (p2.direction.length, p1.direction.length)
#avoid sticky problem
angle = 0.5 * math.pi + tangent
overlap = 0.5 * (p1.size + p2.size - distance + 1)
p1.pos.x += math.sin(angle) + overlap
p1.pos.y -= math.cos(angle) + overlap
p2.pos.x -= math.sin(angle) + overlap
p2.pos.y += math.cos(angle) + overlap
示例14: __init__
def __init__(self, ax, ay, bx=0.0, by=0.0):
"Start and end are Vectors"
if isinstance(ax, Vector) and isinstance(ay, Vector):
self.start = ax
self.end = ay
else:
self.start = Vector(ax, ay)
self.end = Vector(bx, by)
示例15: testManyRemoves
def testManyRemoves(self):
vec = Vector()
for i in range(50, BIG_VEC_SIZE):
vec.append(i)
for i in range(50):
self.bigVec.remove(i)
self.assertEquals(vec, self.bigVec)