Advertisement
niromru

Untitled

Mar 2nd, 2022
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from math import sqrt
  2.  
  3. def is_inside(x, y, x1, y1, x2, y2, x3, y3):
  4.     s = get_square(x1, y1, x2, y2, x3, y3)
  5.     s1 = get_square(x, y, x2, y2, x3, y3)
  6.     s2 = get_square(x1, y1, x, y, x3, y3)
  7.     s3 = get_square(x1, y1, x2, y2, x, y)
  8.     s_new = s1 + s2 + s3
  9.     pogr = 0.01
  10.     return abs(s_new - s) < pogr
  11.  
  12.  
  13. def get_square(x1, y1, x2, y2, x3, y3):
  14.     a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
  15.     b = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3))
  16.     c = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3))
  17.     p = (a + b + c) / 2
  18.     try:
  19.         s = sqrt(p * (p - a) * (p - b) * (p - c))
  20.     except ValueError:
  21.         print(p - a, p - b, p - c)
  22.         return False
  23.     return s
  24.  
  25.  
  26. tr = '''4 10 10 4 1 1
  27. -7 10 0 3 -10 0
  28. 17 23 -1 2 -1 23
  29. -77 -10 -5 -20 -80 -23
  30. 4 1 5 9 5 1
  31. -12 20 -10 8 -10 20
  32. 60 60 90 93 90 60
  33. 3 0 20 23 0 20
  34. -7 -30 10 -47 10 -30
  35. -10 40 25 -7 -13 -10'''.split('\n')
  36. x1, y1, x2, y2, x3, y3 = map(int, tr[0].split())
  37. for x in range(-100, 101):
  38.     for y in range(-100, 101):
  39.         if is_inside(x, y, x1, y1, x2, y2, x3, y3):
  40.             pass
  41.             #print(x, y)
  42. #print(tr)
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement