Guest User

Untitled

a guest
May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. from math import sqrt
  2.  
  3. def get_distance(first_coord, second_coord):
  4. """
  5. Get the distance between two points in the cartesian plane.
  6.  
  7. Parameters
  8. ----------
  9.  
  10. first_coord: tuple
  11. Position x and y of first point.
  12.  
  13. second_coord: tuple
  14. Position x and y of second point.
  15.  
  16. Returns
  17. -------
  18.  
  19. The distance.
  20. """
  21.  
  22. x1, y1 = first_coord
  23. x2, y2 = second_coord
  24.  
  25. distance = sqrt((y2-y1)**2 + (x2-x1)**2)
  26.  
  27. return distance
  28.  
  29. def avg_distance(first_coord, second_coord, third_coord):
  30. """
  31. Get the average distance between three points.
  32.  
  33. Parameters
  34. ----------
  35.  
  36. first_coord: tuple
  37. Position x and y of first point.
  38.  
  39. second_coord: tuple
  40. Position x and y of second point.
  41.  
  42. third_coord: tuple
  43. Position x and y of second point.
  44.  
  45. Returns
  46. -------
  47.  
  48. The average distance.
  49. """
  50.  
  51. # Get distances
  52. dist_1 = get_distance(first_coord, second_cord)
  53. dist_2 = get_distance(first_coord, third_cord)
  54. dist_3 = get_distance(second_coord, third_cord)
  55.  
  56. avg = (dist_1 + dist_2 + dist_3)/3
  57.  
  58. return avg
Add Comment
Please, Sign In to add comment