Natalia__krkrkr

Попадание точки в окружность

Aug 12th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import math
  2. data = input("Введите X,Y,R ")
  3. m_data = data.split(" ")
  4. print(m_data)
  5. x = float(m_data[0])
  6. y = float(m_data[1])
  7. r = float(m_data[2])
  8. upper_right = [math.ceil(x+r), math.ceil(y+r)]
  9. lower_left = [math.ceil(x-r), math.ceil(y-r)]
  10. print(upper_right)
  11. print(lower_left)
  12. m_coordinates = []
  13. counter = 0
  14. xy = []
  15. i = 1
  16. step = math.ceil(r)*2+1
  17. for i in range(abs(int(lower_left[1])-int(upper_right[1]))+1):
  18.     for j in range(abs(int(lower_left[0]) - int(upper_right[0])) + 1):
  19.         point = [math.ceil(x-r)+j, math.ceil(y-r)+i]
  20.         m_coordinates.append(point)
  21.     print(m_coordinates[i*step:i*step+step])
  22. for num in range(len(m_coordinates)):
  23.     x_num = int(m_coordinates[num][0])
  24.     y_num = int(m_coordinates[num][1])
  25.     if (((x_num-x)**2) + ((y_num-y)**2)) <= (r**2):
  26.         counter = counter + 1
  27. print(counter)
Advertisement
Add Comment
Please, Sign In to add comment