Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def total_dist_x_y(coord_list):
- """ Total distance traveled: X + Y """
- total = 0
- stop_at = len(coord_list) - 1
- for i in range(0,stop_at):
- x1 = coord_list[i][0]
- y1 = coord_list[i][1]
- x2 = coord_list[i+1][0]
- y2 = coord_list[i+1][1]
- x_dist = abs(x1-x2)
- y_dist = abs(y1-y2)
- dist_traveled = x_dist + y_dist
- total += dist_traveled
- return total
- def total_dist_diagonal(coord_list):
- """ Total distance traveled between points """
- total = 0
- stop_at = len(coord_list) - 1
- for i in range(0,stop_at):
- x1 = coord_list[i][0]
- y1 = coord_list[i][1]
- x2 = coord_list[i+1][0]
- y2 = coord_list[i+1][1]
- x_dist = abs(x1-x2)
- y_dist = abs(y1-y2)
- dist_traveled = math.sqrt(x_dist**2 + y_dist**2)
- total += dist_traveled
- return total
Advertisement
Add Comment
Please, Sign In to add comment