本文整理汇总了Python中Vector.Vector.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.clone方法的具体用法?Python Vector.clone怎么用?Python Vector.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testludecomp
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import clone [as 别名]
def testludecomp(self):
# TODO: Fix this test and the function under test!
return
A = Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
m2 = A.clone()
(index, d) = m2.ludecomp()
b = Vector(6, -1, 3)
x = m2.lubacksub(index, b.clone())
assert(False)
示例2: __init__
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import clone [as 别名]
class Wall:
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)
def projection(self, p):
"""Return the projection of a point on this wall.
If the point is outside the wall, return the nearest end point."""
# From http://www.codeguru.com/forum/showthread.php?t=194400:
#
# Let the point be C (Cx,Cy) and the line be AB (Ax,Ay) to (Bx,By).
# Let P be the point of perpendicular projection of C on AB. The parameter
# r, which indicates P's position along AB, is computed by the dot product
# of AC and AB divided by the square of the length of AB:
# (1) AC dot AB
# r = ---------
# ||AB||^2
# r has the following meaning:
# r=0 P = A
# r=1 P = B
# r<0 P is on the backward extension of AB
# r>1 P is on the forward extension of AB
# 0<r<1 P is interior to AB
# The point P can then be found:
# Px = Ax + r(Bx-Ax)
# Py = Ay + r(By-Ay)
# And the distance from A to P = r*L."""
AC = p-self.start
AB = self.end-self.start
r = AC.dot(AB)/self.length()**2
if r > 1:
# The point p is past the end of the wall
return self.end
if r < 0:
# The point p is past the beginning of the wall
return self.start
return Vector(self.start.x + r*(self.end.x-self.start.x),
self.start.y + r*(self.end.y-self.start.y))
def distance_to(self, p):
"""The shortest distance from the wall to point p."""
return self.projection(p).distance_to(p)
def length(self):
return self.start.distance_to(self.end)
def clone(self):
return Wall(self.start.clone(), self.end.clone())