Guest User

Untitled

a guest
Nov 19th, 2018
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. class Dot:
  5. def __init__(self):
  6. self.x = 0
  7. self.y = 0
  8.  
  9. def __init__(self, x1, y1):
  10. self.x = x1
  11. self.y = y1
  12.  
  13. def distance(self, d):
  14. a = ( (self.x - d.x)**2 + (self.y - d.y)**2 )**(0.5)
  15. return a
  16.  
  17. #///////////////////////////////////////////////////////
  18. class Trangle:
  19. def __init__(self, dot_a, dot_b, dot_c):
  20. self.a = dot_a
  21. self.b = dot_b
  22. self.c = dot_c
  23.  
  24. def p(self):
  25. p = self.a.distance(self.b) + self.c.distance(self.b) + self.a.distance(self.c)
  26. return p
  27.  
  28. def s(self):
  29. p = self.p()/2
  30. s = (p * (p - self.a.distance(self.b)) * (p - self.c.distance(self.b)) * (p - self.a.distance(self.c)) )**(0.5)
  31. return s
  32.  
  33. def isExists(self):
  34. bol = True
  35. if(self.a.distance(self.b) + self.c.distance(self.b) <= self.a.distance(self.c) and
  36. (self.a.distance(self.c)+ self.c.distance(self.b) <= self.a.distance(self.b)) and
  37. (self.a.distance(self.b) + self.a.distance(self.c) <= self.c.distance(self.b))):
  38. bol = False
  39. return bol
  40.  
  41. #///////////////////////////////////////////////////////
  42. dot_1 = Dot(0,0)
  43. dot_2 = Dot(5,5)
  44. dot_3 = Dot(5,2)
  45.  
  46. trang = Trangle(dot_1, dot_2, dot_3)
  47.  
  48. print(trang.p())
  49. print(trang.s())
  50. print(trang.isExists())
Add Comment
Please, Sign In to add comment