本文整理汇总了Python中Vector.Vector.multiply方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.multiply方法的具体用法?Python Vector.multiply怎么用?Python Vector.multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.multiply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collisionActor
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import multiply [as 别名]
def collisionActor(self, actor):
if not actor.bbox.overlaps(self.bbox):
return False, Vector(0,0)
# Line segment 1: p + t*r
# Line segment 2: q + u*s
p = Vector(actor.location.x, actor.location.y-actor.height/2)
r = Vector(0, actor.height-1)
size = len(self.vertices)
for vertex in range(size):
# t = (q - p) x s /(r x s)
# u = (q - p) x r /(r x s)
q = self.vertices[vertex]
qPlusS = self.vertices[(vertex+1)%size]
s = qPlusS.subtract(q)
t, u = Polygon.__LineSegmentIntersection__(p, r, q, s)
if t >= 0 and t < 1 and u >= 0 and u < 1:
# return True, p.add(r.multiply(t)).add(r.multiply(0.5))
return True, r.multiply(t)#.add(Vector(0, -.001))
return False, Vector(0,0)
示例2: distanceFromPointToLine
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import multiply [as 别名]
def distanceFromPointToLine(line):
"""
from Wikipedia: http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
distance = |(a - p) - ((a - p) dot n * n)|
where a is a point on the line, p is a point in space, and n is the normal direction of the line.
"""
a = Vector(line.x0, line.y0, line.z0) # start point of line (this can be any point on the line)
p = Vector(mousePosition[0], mousePosition[1], mousePosition[2]) # vector pointing to current mouse location
n = Vector(line.x1 - line.x0, line.y1 - line.y0, line.z1 - line.z0).normal() # unit vector along direction of line
aMinusP = a.subtract(p)
dirNorm = aMinusP.subtract(n.multiply(aMinusP.dotProduct(n))) # this is the direction normal to the line
disNorm = dirNorm.length # this is the distance normal to the line
startPoint = Vector(line.x0, line.y0, line.z0)
endPoint = Vector(line.x1, line.y1, line.z1)
mousePoint = Vector(mousePosition[0], mousePosition[1], mousePosition[2])
endVector = mousePoint.subtract(endPoint)
#print("Distance End = " + str(distanceEnd))
startVector = mousePoint.subtract(startPoint)
#print("Distance Start = " + str(distanceStart))
distanceEnd = endVector.length
distanceStart = startVector.length
#check to see if the normal line falls outside of the line we're measuring to
normPoint = [dirNorm.x + mousePoint.x, dirNorm.y + mousePoint.y]
if line.isPointOnLine(normPoint):
short = 'norm'
distance = disNorm
elif distanceEnd <= distanceStart:
short = 'end'
distance = distanceEnd
else:
short = 'start'
distance = distanceStart
#print("NORMDIST = " + str(disNorm) + " START/END = " + str(distanceEnd) + " " + str(distanceStart))
#print("ANGLE = " + str(angle))
"""
glLineWidth(1.0)
glBegin(GL_LINES)
glColor3f(0.0, 0.0, 0.0) # black
if short == 'start':
# print("NORMSTART = " + "(" + str(dirNorm.x) + ", " + str(dirNorm.y) + ")")
# print("START = " + "(" + str(startPoint.x) + ", " + str(startPoint.y) + ")")
# print("MOUSE = " + "(" + str(mousePoint.x) + ", " + str(mousePoint.y) + ")")
glVertex3f(mousePoint.x, mousePoint.y, 0.0)
glVertex3f(startPoint.x, startPoint.y, 0.0)
if short == 'end':
# print("NORMEND = " + "(" + str(dirNorm.x) + ", " + str(dirNorm.y) + ")")
glVertex3f(mousePoint.x, mousePoint.y, 0.0)
glVertex3f(endPoint.x, endPoint.y, 0.0)
if short == 'norm':
glVertex3f(mousePoint.x, mousePoint.y, 0.0)
glVertex3f(dirNorm.x + mousePoint.x, dirNorm.y + mousePoint.y, 0.0)
glEnd()
"""
return distance