def get_instructions(pts): instr = [] angle = 0 for i in range(len(pts) - 1): if pts[i+1] == pts[i]: continue dp = pt_diff(pts[i+1], pts[i]) na = round(np.arctan2(dp[0], dp[1]) * 2 / math.pi) * 90 da = na - angle if da > 180: da -= 360 elif da <= -180: da += 360 angle = na dist = abs(sum(dp)) instr.append('{} {:.0f}\nforward {:.0f}'.format('left' if da > 0 else 'right', abs(da), dist)) return instr
def simplify(pts): res = [pts[0]] for i in range(len(pts) - 2): if pt_diff(pts[i+1], pts[i]) != pt_diff(pts[i+2], pts[i+1]): res.append(pts[i + 1]) return res