-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabs7_1.py
64 lines (52 loc) · 1.65 KB
/
Labs7_1.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
56
57
58
59
60
61
62
63
64
import math
class Sphere(object):
# radius = 1.0
# x = 0
# y = 0
# z = 0
def __init__(self, radius, x=0, y=0, z=0):
self.radius = radius
self.x = x
self.y = y
self.z = z
def get_volume(self): # Calculate the volume
volume = (4 / 3) * math.pi * math.pow(self.radius, 3)
return volume
def get_square(self):
square = 4 * math.pi * math.pow(self.radius, 2)
return square
def get_radius(self):
return self.radius
def get_center(self):
coordinats = tuple((self.x, self.y, self.z))
return coordinats
def set_radius(self, r):
self.radius = r
return self
def set_center(self, x, y, z):
self.x = x
self.y = y
self.z = z
def is_point_inside(self, x, y, z):
delta_x = self.x - x
delta_y = self.y - y
delta_z = self.z - z
distance_center_point = math.pow(delta_x, 2) + math.pow(delta_y, 2) + math.pow(delta_z, 2)
if distance_center_point <= math.pow(self.radius, 2):
return True
else:
return False
s0 = Sphere(0.5)
print("Proba")
print(s0.get_center()) # (0.0, 0.0, 0.0)
print(s0.get_volume(), 0.523598775598, "Works")
print(s0.get_square(), "Works")
print (s0.is_point_inside(0, -1.5, 0), "False") #
print(s0.get_radius(), "Works")
s0.set_radius(1.6)
print (s0.is_point_inside(0, -1.5, 0), "True") #
print(s0.get_radius(), "__", s0.get_volume(), 0.523598775598) # 1.6
print(s0.get_square())
s0.set_center(5.1, -2, 1.1)
print(s0.get_center()) # (0.0, 0.0, 0.0)
print("Finish")