当前位置: 首页>>代码示例>>Python>>正文


Python Vector.normalized方法代码示例

本文整理汇总了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))
开发者ID:aenfield,项目名称:UdacityLinearAlgebra,代码行数:9,代码来源:vector_test.py

示例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
开发者ID:baskus,项目名称:graphbots,代码行数:27,代码来源:car.py

示例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)
开发者ID:aenfield,项目名称:UdacityLinearAlgebra,代码行数:10,代码来源:vector_test.py

示例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())
开发者ID:aqing1987,项目名称:s-app-layer,代码行数:18,代码来源:test-magnitude-and-direction.py

示例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])
开发者ID:ehafenmaier,项目名称:twd-udacity-la-refresher,代码行数:33,代码来源:lesson.py


注:本文中的vector.Vector.normalized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。