-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.py
55 lines (47 loc) · 1.05 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
44
45
46
47
48
49
50
51
52
53
54
55
import math
class Point(object):
"""
Example:
p1 = Point(1,1,1)
p2 = Point(2,2,2)
p1.distance(p2)
>>> 1.73205...
p1.move(0, 1, 0)
print(p1)
>>> Point(1, 2, 1)
p1.get_x()
>>> 1
"""
def __init__(self, x, y, z):
"""
:param x: float
:param y: float
:param z: float
"""
self.x = x
self.y = y
self.z = z
def move(self, dx=0, dy=0, dz=0):
"""
:param dx: float
:param dy: float
:param dz: float
:return: None
"""
self.x += dx
self.y += dy
self.z += dz
def __str__(self):
return f"Point({self.x}, {self.y}, {self.z})"
def get_x(self):
return self.x
def get_y(self):
return self.y
def get_z(self):
return self.z
def distance(self, p):
dx = self.x - p.x
dy = self.y - p.y
dz = self.z - p.z
dp = math.sqrt(dx**2 + dy**2 + dz**2)
return dp