本文整理汇总了Python中vector.Vector类的典型用法代码示例。如果您正苦于以下问题:Python Vector类的具体用法?Python Vector怎么用?Python Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: is_parallel
def is_parallel(self, plane1):
# returns if parallel or not
u1 = self.normal_vector
u2 = plane1.normal_vector
u1_vect = Vector(u1)
u2_vect = Vector(u2)
return u1_vect.is_parallel_to(u2_vect)
开发者ID:jonmhong,项目名称:Linear-Algebra,代码行数:7,代码来源:plane.py
示例2: load_myformat
def load_myformat(self, filename):
filetext=file(filename, 'r')
go_lines=filetext.readlines()
header=go_lines[0:6]
self.title=header[1]
self.game_commentary=header[3]
self.setsize(header[5])
movelines=go_lines[7:]
# go_lines=str.splitlines(filetext)
# go_lines=filetext.splitlines()
#
# TODO add the part to read the header and board size
#
for line in movelines:
content=line.split(None,2)
number=content[0]
color=content[1]
pos=Vector()
# pos.fromString3(content[2].strip(" "))
pos.fromString(content[2].strip(" "))
next_move=stone.Stone(number,color,pos)
self.moves.append(next_move)
开发者ID:ludl,项目名称:radialf,代码行数:26,代码来源:boardgame.py
示例3: mutateAt
def mutateAt(self, index):
result = False
blob = self.blobs[index]
newBlob = blob.clone()
newBlob.radius += 1
if not self.validate(newBlob):
for i in range(5):
offset = Vector.randomUnitCircle() * random()*i
newBlob.pos += offset
if self.validate(newBlob):
result = True
break
else:
result = True
if not result and random() > 0.5:
newBlob.radius -= 1
for i in range(5):
offset = Vector.randomUnitCircle() * random()*i
if self.validate(newBlob):
result = True
if result:
self.blobs[index] = newBlob
return result
开发者ID:fablab-ka,项目名称:cityscape,代码行数:31,代码来源:blobmanager.py
示例4: make_matrix
def make_matrix(vector_list):
'''
Make a matrix out of a list of vectors 'vector_list'
Just like make_vector in the vector module, this decides whether to instantiate the FullMatrix or SparseMatrix class
by using the is_zero method of the Vector class
'''
count = 0
for vector1 in vector_list:
vector_obj = Vector(vector1, zero_test = lambda x : (x == 0))
if(vector_obj.is_zero()==True):
count = count+1
if((count/len(vector_list))>DENSITY_THRESHOLD and len(vector_list)>SIZE_THRESHOLD):
i = 0
matrix_elmts = []
matrix_indices = []
while(i<len(vector_list)):
vector_obj1 = Vector(vector_list[i] , zero_test = lambda x : (x == 0))
if(vector_obj1.is_zero()==True):
matrix_elmts.append(vector_list[i])
matrix_indices.append(i)
i = i+1
else:
i = 0
matrix_elmts = []
while(i<len(vector_list)):
matrix_elmts.append(vector_list[i])
i = i+1
开发者ID:Amit-Tomar,项目名称:Parametrized-String-Matching-Implementation-for-Software-Plagiarism-Check,代码行数:27,代码来源:IMT2013031_matrix.py
示例5: __init__
def __init__(self, x=50, y=50):
self.pos = Vector(x, y);
self.speed = Vector();
self.accel = Vector();
self.angle = 0;
self.tmpAngle = 0;
self.canShoot = 1;
self.shootLimiter = Timer(2);
self.keyb = 1;
self.keys = {
"up":0,
"down":0,
"left":0,
"right":0,
"shoot":0
};
self.mouse = Vector(0,0);
self.mShoot = 0;
self.accel.x = 1;
self.points = (
Vector(0,-10),
Vector(0,10),
Vector(30,0)
);
开发者ID:strykejern,项目名称:strykejern-pythonGame,代码行数:26,代码来源:ship.py
示例6: __init__
def __init__(self, minimum, maximum, target_minimum=None, target_maximum=None):
self.minimum = minimum
self.maximum = maximum
# Ratio is depended of latitude. It is always <= 1.
# In one latitude degree is always 40 000 / 360 km.
# In one current longitude degree is about 40 000 / 360 * ratio km.
ratio = math.sin((90.0 - ((self.maximum.lat + self.minimum.lat) / 2.0)) / 180.0 * math.pi)
# Longitude displayed as x.
# Latitude displayed as y.
# Ratio is x / y.
space = Vector()
current_ratio = (self.maximum.lon - self.minimum.lon) * ratio / (self.maximum.lat - self.minimum.lat)
target_ratio = (target_maximum.x - target_minimum.x) / (target_maximum.y - target_minimum.y)
if current_ratio >= target_ratio:
n = (target_maximum.x - target_minimum.x) / (maximum.lon - minimum.lon) / ratio
space.y = ((target_maximum.y - target_minimum.y) - (maximum.lat - minimum.lat) * n) / 2.0
space.x = 0
else:
n = (target_maximum.y - target_minimum.y) / (maximum.lat - minimum.lat) * ratio
space.x = ((target_maximum.x - target_minimum.x) - (maximum.lon - minimum.lon) * n) / 2.0
space.y = 0
self.target_minimum = target_minimum + space
self.target_maximum = target_maximum - space
self.space = space
开发者ID:enzet,项目名称:Roentgen,代码行数:32,代码来源:flinger.py
示例7: test_copy
def test_copy():
vec = Vector(1, 2, 3)
vec_copy = vec.copy()
vec_copy += 100
assert vec != vec_copy
开发者ID:Potato42,项目名称:arbitrary-vector,代码行数:7,代码来源:test_vector.py
示例8: __init__
def __init__(self,n,x,y):
brain = Perceptron(n,0.001)
self.location = Vector([x,y])
self.velocity = Vector([0,0])
self.acceleration = Vector([0,0])
self.maxforce = 0.1
self.maxspeed = 4
开发者ID:EricSchles,项目名称:neuralnet,代码行数:7,代码来源:second.py
示例9: reflex_factor
def reflex_factor(self, eartip):
A, B, C = self.tri_at(eartip)
AB = B - A
BC = C - B
# vector pointing outside
AB_out = Vector.cross(AB, self.normal).unit()
return Vector.dot(AB_out, BC.unit())
开发者ID:Anti-Mage,项目名称:ogre,代码行数:7,代码来源:pgon.py
示例10: fromelement
def fromelement(cls, maptree, terrainmap=None, tokenmap=None):
# get the size
esize = maptree.find("size")
if esize is None:
raise MapError("A map must have a size")
else:
evec = esize[0]
size = Vector.fromelement(evec)
# and the origin
eorigin = maptree.find("origin")
if eorigin is not None:
evec = eorigin[0]
origin = Vector.fromelement(evec)
else:
origin = Vector.ORIGIN
# and the name, game and copyright
hm = cls(size, origin)
# add the terrains
for eterrain in maptree.findall("terrain"):
tname = eterrain.get("type")
if tname in terrainmap:
terrain = terrainmap[tname].fromelement(eterrain, hm)
hm.addTerrain(terrain)
else:
print "terrain name %s not in terrain map %s" % (tname, terrainmap)
return hm
开发者ID:markllama,项目名称:hexgame-research,代码行数:31,代码来源:map.py
示例11: calculateLocation
def calculateLocation(self, robot_classification, bucket):
''' If the location can be taken from the bucket, return the mean '''
if bucket is not None and len(bucket) > 1:
points = [x for (x, _) in bucket]
return meanPoint(points)
if not self.previous_locations[robot_classification].full():
return None
''' Get the ArrayQueue(previous locations) for robot with the 'key' identifier '''
points_queue = self.previous_locations[robot_classification]
trajectory_vector = linear_regression(points_queue)
if trajectory_vector is None:
return None
trajectory_vector.rescale(1)
speed = self.getSpeed(robot_classification)
dislocation = Vector.scalarMultiple(trajectory_vector, speed)
prev_location = points_queue.getLeft()
estimated_robot_position = Vector.addToPoint( prev_location, dislocation )
if self.outOfBounds(estimated_robot_position):
return None
return estimated_robot_position
开发者ID:pbsinclair42,项目名称:SDP-2016,代码行数:27,代码来源:tracker.py
示例12: tangentOnCurve
def tangentOnCurve(self ,param = 0.5 ,normalize = 1 ):
'''
This function computes the tangent at the given parameter along the curve
@type param : float
@param param : At what value along the curve to sample
@type normalize : bool
@param normalize : whether or not to normalize the output tangent
@return Vector
'''
order = self.degree + 1
pos = Vector([0,0,0])
#methodA
for i in range(len(cp)-1) :
#First compute the basis
basis = bsplineBasis(self.knots ,i+1,order-1 , param)
#Then compute the Q parameter which is the derivative multiplier based on the -1 +1 control points
q = Vector((degree /(self.knots[i+degree +1] - self.knots[i+1])) * (self.controlPoints[i+1] - self.controlPoints[i]))
pos+= (basis*q)
if normalize == 1 :
return pos.normalize()
else :
return pos
开发者ID:Narinyir,项目名称:python_misc,代码行数:27,代码来源:bezier_curve.py
示例13: cull_faces
def cull_faces(self, view_vector):
"""
Given a Vector representing the view, this method returns a copy of
this PolygonMatrix minus all the faces that are not visible to the view.
view_vector: Vector, the view vector to cull in relation to.
"""
if not isinstance(view_vector, Vector):
raise TypeError("%s is not valid view Vector" % view_vector)
culled_polygonmatrix = PolygonMatrix()
for polygon in self:
v1 = Vector([
polygon[2][0] - polygon[0][0],
polygon[2][1] - polygon[0][1],
polygon[2][2] - polygon[0][2]
])
v2 = Vector([
polygon[1][0] - polygon[0][0],
polygon[1][1] - polygon[0][1],
polygon[1][2] - polygon[0][2]
])
normal = Vector.cross(v1, v2)
if Vector.dot(normal, view_vector) < 0:
culled_polygonmatrix.add_polygon(*polygon)
return culled_polygonmatrix
开发者ID:omgimanerd,项目名称:graphics,代码行数:25,代码来源:matrix.py
示例14: test_invert_vector
def test_invert_vector():
"""Test inverting a Vector"""
vector1 = Vector([5, 5])
answer = Vector([-5, -5])
invert_vector = vector1.invert_vector()
assert invert_vector == answer
开发者ID:madhavajay,项目名称:ud953,代码行数:7,代码来源:vector_test.py
示例15: draw_arrow
def draw_arrow(canvas, point_from, point_to, color=Color(), width=1.0):
"""
@type canvas: drawing.canvas.Canvas
@type point_from: vector.Vector
@type point_to: vector.Vector
@type color: Color
@type width: float
"""
point_from = Vector.vectorize(point_from)
point_to = Vector.vectorize(point_to)
DrawingUtils.draw_line(canvas, point_from, point_to, color, width)
vec_arrow = point_to.sub(point_from)
wing = vec_arrow.inverse().normalized().scaled(10)
wing_right = wing.rotate(45)
wing_left = wing.rotate(-45)
DrawingUtils.draw_line(canvas, point_to,
wing_right.add(point_to), color,
width)
DrawingUtils.draw_line(canvas, point_to,
wing_left.add(point_to), color,
width)
开发者ID:Kobzol,项目名称:debug-visualizer,代码行数:25,代码来源:drawable.py
示例16: test_eq
def test_eq(self):
v5 = Vector(0,0)
v5.x = 5
v5.y = 5
#self.assertEqual(v5,self.vec5)
self.assertTrue(v5 == self.vec5)
self.assertTrue((v5 == self.vec1) is False)
开发者ID:Narcolapser,项目名称:Gedit-PyUnit-Plugin,代码行数:7,代码来源:test_vector.py
示例17: test_ne
def test_ne(self):
v5 = Vector(0,0)
v5.x = 5
v5.y = 5
self.assertEqual(v5,self.vec5)
self.assertTrue(v5 != self.vec1)
self.assertTrue((v5 != self.vec5) is False)
开发者ID:Narcolapser,项目名称:Gedit-PyUnit-Plugin,代码行数:7,代码来源:test_vector.py
示例18: scan
def scan(self, bot):
# menor distancia ate agora
menor = VISAO
ind = -1
# itera todos bots
for b in self.bots:
# se nao eh o proprio e esta ativo
if b is not bot and b.ativo:
# calcula distancia entre os bots
distancia = (bot.posicao - b.posicao).length()
# verifica se a distancia esta dentro do limiar aceitavel
# e eh menor que a menor encontrada ate agora
if distancia-RAIO <= VISAO and distancia < menor:
vet_canhao = Vector(cos(bot.direcao + bot.canhao), sin(bot.direcao + bot.canhao))
vet_alvo = b.posicao - bot.posicao
angulo = vet_canhao.angle(vet_alvo)
if angulo <= mod(bot.arco/2.0 + atan2(RAIO, (bot.posicao - b.posicao).length()), PI):
ind = b.indice
menor = distancia
return menor, ind
开发者ID:rodrigosetti,项目名称:pythonbots,代码行数:25,代码来源:arena.py
示例19: Entity
class Entity(pygame.sprite.Sprite):
def __init__(self, bounds=[0,600,0,800], size=(4,4)):
pygame.sprite.Sprite.__init__(self)
self.__update_surface_size(size) #creates scope variable "image", which is a pygame surface
self.alive = True
self.bounds = bounds
self.vector = Vector()
def die(self):
self.alive = False
self.vector.dx = 0
self.vector.dy = 0
def update(self, timestep = 1):
self.update_position(timestep)
def __update_position(self, timestep = 1):
self.vector.update(timestep)
def __update_surface_size(self, size=(1,1)):
self.image = pygame.Surface(size)
def set_size(self, size=(1,1)):
self.update_surface_size(size)
@property
def orientation(self):
return self.vector.orientation()
@property
def rect(self):
return self.image.get_rect(topleft=(self.vector.x,self.vector.y))
开发者ID:zceeg70,项目名称:GeneticBugGame,代码行数:32,代码来源:entityConfig.py
示例20: apply
def apply(boids, bj):
pcj = Vector()
for b in boids:
if b != bj:
pcj.sum(b.position)
pcj = pcj.div(len(boids) - 1)
return pcj.minus(bj.position).div(100)
开发者ID:lorenzo85,项目名称:python-playground,代码行数:7,代码来源:boidsrules.py
注:本文中的vector.Vector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论