-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4rectangle.py
More file actions
30 lines (27 loc) · 920 Bytes
/
test4rectangle.py
File metadata and controls
30 lines (27 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from math import sqrt
class Point(object):
"Définition d'un point géométrique"
def __init__(self,x,y):
self.x = x
self.y = y
def affiche_point(self,p):
print("coord. horizontale =", p.x, "coord. verticale =", p.y)
def distance(self,p1, p2):
# On applique le théorème de Pythagore :
dx =abs(p1.x - p2.x)
# abs() => valeur absolue
dy =abs(p1.y - p2.y)
return sqrt(dx*dx + dy*dy)
class Rectangle(object):
"définition d'une classe de rectangles"
def __init__(self,largeur,longueur,coin):
self.la = largeur
self.lo = longueur
self.coin = Point(coin.x,coin.y)
def calculSurface(self):
print ("surface = %.2f m2" %(self.la * self.lo))
def trouveCentre(self):
p = Point(x = 0,y =0)
p.x = self.coin.x + self.la/2.0
p.y = self.coin.y + self.lo/2.0
print(p)