def heading_toward(self, to_pixel: Pixel_xy): """ The heading to face from the from_pixel to the to_pixel """ # Make the default heading 0 if from_pixel == to_pixel. if self == to_pixel: return 0 delta_x = to_pixel.x - self.x delta_y = to_pixel.y - self.y new_heading = utils.dxdy_to_heading(delta_x, delta_y, default_heading=0) return new_heading
def average_of_headings(self, agent_set, fn): """ fn extracts a heading from an agent. This function returns the average of those headings. Cannot be static because fn may refer to self. agent_set may not be all the agents. So it must be passed as an argument. """ # dx and dy are the x and y components of traveling one unit in the heading direction. dx = mean([utils.dx(fn(agent)) for agent in agent_set]) dy = mean([utils.dy(fn(agent)) for agent in agent_set]) return utils.dxdy_to_heading(dx, dy, default_heading=self.heading)