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