- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_exp1.py
More file actions
Latest commit
27 lines (27 loc) · 1015 Bytes
/
Copy pathclass_exp1.py
File metadata and controls
27 lines (27 loc) · 1015 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
importmath
importnumpyasnp
print(__name__)
fromkivy.appimportApp
classPoint:
'Represents a point in two-dimensional geometric coordinates'
def__init__(self, x=0, y=0):
'''Initialize the position of a new point. The x and y
coordinates can be specified. If they are not, the point
defaults to the origin.'''
self.move(x, y)
defmove(self, x, y):
"Move the point to a new location in two-dimensional space."
self.x=x
self.y=y
defreset(self):
'Reset the point back to the geometric origin: 0, 0'
self.move(0, 0)
defcalculate_distance(self, other_point):
"""Calculate the distance from this point to a second point
passed as a parameter.
This function uses the Pythagorean Theorem to calculate
the distance between the two points. The distance is returned
as a float."""
returnmath.sqrt(
(self.x-other_point.x)**2+
(self.y-other_point.y)**2)