本文整理汇总了Python中Vector.Vector.projection_length方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.projection_length方法的具体用法?Python Vector.projection_length怎么用?Python Vector.projection_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.projection_length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_acceleration
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import projection_length [as 别名]
def calculate_acceleration(self, walls, actors):
# To compute the impatience factor, we need the average velocity,
# in the direction of desired movement.
#
# This is found by projecting the direction we have moved onto the
# vector from the initial position to the target and computing the
# distance from this projection. The distance travelled is then
# converted to an average velocity my dividing with the time
if self.time == 0.0:
average_velocity = 0.0
else:
proj = Vector.projection_length(
self.initial_position, self.target, self.position)
average_velocity = proj / self.time
# The impatience factor is given by the average velocity divided
# by the *initial* desired velocity. (6) in the article
impatience = 1.0 - average_velocity / self.initial_desired_velocity
# (5) in the article
desired_velocity = (1.0-impatience) * self.initial_desired_velocity + \
impatience * self.max_velocity
towards_target = (self.target - self.position).normal()
#desired_acceleration = (1.0/self.relax_time) * \
#(desired_velocity * towards_target - self.velocity)
towards_target *= desired_velocity
towards_target -= self.velocity
towards_target *= (1.0/self.relax_time)
self.acceleration = towards_target
repelling_forces = list()
for b in actors:
if self == b:
continue
radius_sum = b.radius + self.radius
from_b = self.position - b.position
distance = from_b.length()
from_b.normalize(distance)
from_b *= pm.constants.a_2 * \
numpy.exp((radius_sum-distance)/pm.constants.b_2)
repelling_forces.append(from_b)
for f in repelling_forces:
self.acceleration += f