Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def get_triangle(a, b, c, d):
- '''
- @param: celkem 4 body ve formatu (x, y)
- @return: 3 body ktere tvori nejvetsi trojuhelnik
- '''
- t = []
- trojuhelniky = [ [a, b, c], [a, b, d], [a, c, d], [b, c, d] ]
- for troj in trojuhelniky:
- p1 = trojuhelnik(troj[0], troj[1], troj[2])
- if p1.jeTrojuhelnik():
- t.append(p1)
- biggest = t[0]
- for i in range(1, len(t)):
- if (t[i].obsah > biggest.obsah):
- biggest = t[i]
- return biggest.b1, biggest.b2, biggest.b3, biggest.obsah
- class bod:
- '''
- datovy typ pro bod
- '''
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def __repr__(self):
- return repr((self.x, self.y))
- class trojuhelnik:
- '''
- datovy typ pro trojuhelnik
- '''
- def __init__(self, b1, b2, b3):
- self.b1 = b1
- self.b2 = b2
- self.b3 = b3
- self.s1 = self.vzdalenostDvouBodu(b1, b2)
- self.s2 = self.vzdalenostDvouBodu(b2, b3)
- self.s3 = self.vzdalenostDvouBodu(b3, b1)
- self.obsah = ( (self.s1 * self.s2 * self.s3) / 2 )
- self.je = self.jeTrojuhelnik()
- def __repr__(self):
- return repr((self.obsah, self.s1, self.s2, self.s3, self.b1, self.b2, self.b3))
- def vzdalenostDvouBodu(self, b1, b2):
- '''
- Zjisti jak daleko jsou od sebe dva body
- '''
- return math.sqrt( math.pow(b1.x - b2.x, 2) + math.pow(b1.y - b2.y, 2) )
- def jeTrojuhelnik(self):
- '''
- zjisti zda je to trojuhenik
- '''
- strany = [self.s1, self.s2, self.s3]
- strany.sort(reverse = True)
- if (strany[0] < (strany[1] + strany[2]) ):
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment