Yozh2

Circles

Mar 16th, 2022
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import math
  2. def check_intersection(point1, r1, point2, r2):
  3.     x1, y1 = point1
  4.     x2, y2 = point2
  5.  
  6.     # Calculate distance between centers of the circles
  7.     distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
  8.  
  9.     # Check if circles are equal
  10.     if distance == 0 and r1 == r2:
  11.         return True
  12.  
  13.     elif abs(r1-r2) <= distance <= abs(r1+r2):
  14.         return True
  15.  
  16.     else:
  17.         return False
  18.  
  19.  
  20. x1, y1, r1 = [float(i) for i in input().split()]
  21. x2, y2, r2 = [float(i) for i in input().split()]
  22.  
  23. do_intersect = check_intersection((x1, y1), r1, (x2, y2), r2)
  24. print("YES" if do_intersect else "NO")
Advertisement
Add Comment
Please, Sign In to add comment