本文整理汇总了Python中Vector.Vector.subtract方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.subtract方法的具体用法?Python Vector.subtract怎么用?Python Vector.subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.subtract方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distanceFromPointToLine
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import subtract [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