本文整理汇总了Python中vector.Vector.normalized方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.normalized方法的具体用法?Python Vector.normalized怎么用?Python Vector.normalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.normalized方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNormalizedHandlesZeroVectorWithException
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import normalized [as 别名]
def testNormalizedHandlesZeroVectorWithException(self):
v1 = Vector([0,0])
with self.assertRaises(Exception) as context:
v1.normalized()
self.assertTrue('Cannot normalize the zero vector' in str(context.exception))
示例2: Car
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import normalized [as 别名]
class Car(object):
def __init__(self, position):
self.position = position
self.velocity = Vector(0, 0)
self.alive = True
def update(self, dt, height, acceleration, tangent):
drag = -self.velocity.normalized() if self.velocity.length() > 0 else \
Vector(0, 0)
if height > 0:
acc = tangent * acceleration + tangent * GRAVITY.dot(tangent) \
- drag
else:
acc = GRAVITY - drag
velocity_old = self.velocity
self.velocity = self.velocity + acc * dt
# Check death.
impulse = (velocity_old - self.velocity).length()
print "impulse:", impulse
if impulse > 150:
print "DIE!"
self.alive = False
self.position = self.position + self.velocity * dt
示例3: testNormalizationOfAVector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import normalized [as 别名]
def testNormalizationOfAVector(self):
v1 = Vector([4,4])
v1n = v1.normalized()
self.assertAlmostEqual(v1n.coordinates[0], Decimal('0.7071067811865475244008443620'))
self.assertAlmostEqual(v1n.coordinates[1], Decimal('0.7071067811865475244008443620'))
self.assertEqual(round(v1n.magnitude()), 1)
示例4: Vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import normalized [as 别名]
from vector import Vector
v = Vector([-0.221, 7.437])
print(v.magnitude())
v = Vector([8.813, -1.331, -6.247])
print(v.magnitude())
v = Vector([5.581, -2.136])
print(v.normalized())
v = Vector([1.996, 3.108, -4.554])
print(v.normalized())
#v = Vector([0, 0])
#print(v.normalized())
示例5: Vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import normalized [as 别名]
print 'Scalar Multiplication'
print v.times_scalar(s)
# Magnitude
print ''
print 'Magnitude'
v = Vector([-0.221, 7.437])
print format(v.magnitude(), '.5f')
v = Vector([8.813, -1.331, -6.247])
print format(v.magnitude(), '.5f')
# Normalize
print ''
print 'Normalize'
v = Vector([5.581, -2.136])
print v.normalized()
v = Vector([1.996, 3.108, -4.554])
print v.normalized()
# Dot Product
print ''
print 'Dot Product'
v1 = Vector([7.887, 4.138])
v2 = Vector([-8.802, 6.776])
print v1.dot_product(v2)
v1 = Vector([-5.955, -4.904, -1.874])
v2 = Vector([-4.496, -8.755, 7.103])
print v1.dot_product(v2)
# Angles
v1 = Vector([3.183, -7.627])