Skip to content

Instantly share code, notes, and snippets.

@dekoza
Created July 21, 2014 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekoza/67896e2e03a1b82bd80d to your computer and use it in GitHub Desktop.
Save dekoza/67896e2e03a1b82bd80d to your computer and use it in GitHub Desktop.
zabawa z klasami na spotkaniu 6 kursu "Ukąś Pythona"
class Punkt:
def __init__(self, x, y):
self.x = x
self.y = y
def odl_od_punktu(self, other):
odl = ((self.x - other.x)**2 + (self.y - other.y)**2)**0.5
return odl # float
def odl_od_centrum(self):
return self.odl_od_punktu(Punkt(0,0))
class Kolo:
def __init__(self, centrum, r):
"""
Parametry:
centrum - obiekt klasy Punkt()
r - promień
"""
self.r = r
self.cntr = centrum # wer. a
def czy_wewnatrz(self, punkt):
return self.cntr.odl_od_punktu(punkt) <= self.r # wer. a
class Prostokat:
def __init__(self, wierzch1, wierzch2):
"""
wierzch1, wierzch2 - wierzchołki prostokąta, obiekty klasy Punkt
"""
def czy_wewnatrz(self, punkt):
return wynik # bool
def pole(self):
return wynik # float
class Odcinek:
def czy_przecina(self, odc):
return wynik # bool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment