Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- def get_distance(first_coord, second_coord):
- """
- Get the distance between two points in the cartesian plane.
- Parameters
- ----------
- first_coord: tuple
- Position x and y of first point.
- second_coord: tuple
- Position x and y of second point.
- Returns
- -------
- The distance.
- """
- x1, y1 = first_coord
- x2, y2 = second_coord
- distance = sqrt((y2-y1)**2 + (x2-x1)**2)
- return distance
- def avg_distance(first_coord, second_coord, third_coord):
- """
- Get the average distance between three points.
- Parameters
- ----------
- first_coord: tuple
- Position x and y of first point.
- second_coord: tuple
- Position x and y of second point.
- third_coord: tuple
- Position x and y of second point.
- Returns
- -------
- The average distance.
- """
- # Get distances
- dist_1 = get_distance(first_coord, second_cord)
- dist_2 = get_distance(first_coord, third_cord)
- dist_3 = get_distance(second_coord, third_cord)
- avg = (dist_1 + dist_2 + dist_3)/3
- return avg
Add Comment
Please, Sign In to add comment