viligen

closest_point_coordinates

Oct 10th, 2021 (edited)
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. def closest_point(x_1, y_1, x_2, y_2):
  5.     x_closest = x_1
  6.     y_closest = y_1
  7.     distance1 = math.sqrt((math.pow(x1, 2) + math.pow(y1, 2)))
  8.     distance2 = math.sqrt((math.pow(x2, 2) + math.pow(y2, 2)))
  9.  
  10.     if int(distance1) > int(distance2):
  11.         x_closest = x_2
  12.         y_closest = y_2
  13.     return x_closest, y_closest
  14.  
  15.  
  16. x1 = float(input())
  17. y1 = float(input())
  18. x2 = float(input())
  19. y2 = float(input())
  20.  
  21. closest_point_x, closest_point_y = closest_point(x1, y1, x2, y2)
  22. print(f"({math.floor(closest_point_x)}, {math.floor(closest_point_y)})")
  23.  
Add Comment
Please, Sign In to add comment