本文整理汇总了Python中vector.Vector类的典型用法代码示例。如果您正苦于以下问题:Python Vector类的具体用法?Python Vector怎么用?Python Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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)
);
示例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
示例7: test_copy
def test_copy():
vec = Vector(1, 2, 3)
vec_copy = vec.copy()
vec_copy += 100
assert vec != vec_copy
示例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
示例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())
示例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
示例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
示例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
示例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
示例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
示例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)