def draw(self, ax, center=P.zero(), color="black", size=0.5): a1 = S(center, center + self.p1.resize(size)).draw_arrow(ax, color) a2 = S(center, center + self.p2.resize(size)).draw_arrow(ax, color) a3 = patches.Arc((center.x, center.y), size, size, 0, self.p1.angle_degrees(), self.p2.angle_degrees(), color=color) ax.add_patch(a3) return a1 + a2 + [a3]
def align_with_closest_side(self, v): """ Find closest angle in GRegion object to the direction of v (Point object - defines a vector). """ if self.full: return v if not self.regions: return P.zero() sides = [p for r in self.regions for p in r] # List of points describing all angular # edges of regions in GRegion cos = [side.cos(v) for side in sides] maxcos = max(cos) closest = sides[cos.index( maxcos)] # take the maximal cosine between the velocity # direction and the region edges - that is the closest edge. return closest.resize( v.norm()) # resize to speed magnitude (returns velocity direction)