-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.py
43 lines (36 loc) · 1.1 KB
/
point.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
des points du plans
"""
from math import sqrt
from random import uniform
class Point:
"""
un point du plan
"""
def __init__(self, abscisse, ordonnee):
"""
creation d'un point a partir d'une abscisse et d'une ordonnee
"""
self.abscisse = abscisse
self.ordonnee = ordonnee
def __str__(self):
return str(self.abscisse) + "," + str(self.ordonnee)
def distance_a(self, autre_point):
"""
renvoie la distance entre deux points
"""
difference_x = autre_point.abscisse - self.abscisse
difference_y = autre_point.ordonnee - self.ordonnee
return sqrt(difference_x*difference_x + difference_y*difference_y)
def symetrie(self, axe):
"""
retourne le symetrique par rapport à l'axe_vertical
"""
self.abscisse = self.abscisse - 2*(self.abscisse - axe)
def point_aleatoire(largeur=800, hauteur=600):
"""
renvoie un point aleatoire,
x compris entre 0 et largeur
et y entre 0 et hauteur
"""
return Point(uniform(0, largeur), uniform(0, hauteur))