-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses3DShapes.py
123 lines (86 loc) · 3.86 KB
/
Classes3DShapes.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from math import pi, sqrt
from Classes2DShapes import Shape, Square, Circle, Triangle, Rectangle, check_value
class Cube(Shape):
title = 'Куб'
def __init__(self, length: float):
check_value([length])
self.length = length
self.side = Square(self.length)
def area(self) -> float:
return self.side.area() * 6
def radius_into_sphere(self) -> float:
return self.length / 2
def show_info(self) -> None:
print(f'Площадь поверхности {self.title}а = {self.area()}\n'
f'Радиус вписаной сферы в {self.title} = {self.radius_into_sphere()}\n')
class Parallelepiped(Shape):
title = 'Параллелепипед'
def __init__(self, height: float, length: float, width: float):
check_value([height, length, width])
self.height = height
self.length = length
self.width = width
def area(self) -> float:
return 2 * (self.length * self.height + self.length * self.width + self.height * self.width)
def diagonal(self) -> float:
return sqrt(self.length ** 2 + self.height ** 2 + self.width ** 2)
def show_info(self) -> None:
print(f'Площадь поверхности {self.title}а = {self.area()}\n'
f'Диагональ {self.title}а = {self.diagonal()}\n')
class Cylinder(Shape):
title = 'Цилиндр'
def __init__(self, height: float, radius: float):
check_value([height, radius])
self.height = height
self.circle = Circle(radius)
def area(self) -> float:
return self.circle.perimeter() * (self.height + self.circle.radius)
def area_foot(self) -> float:
return self.circle.area()
def show_info(self) -> None:
print(f'Площадь поверхности {self.title}а = {self.area()}\n'
f'Площадь основания {self.title}а = {self.area_foot()}\n')
class Sphere(Shape):
title = 'Сфера'
def __init__(self, radius: float):
check_value([radius])
self.radius = radius
def area(self):
return 4 * pi * self.radius ** 2
def volume(self) -> float:
return 4 / 3 * pi * self.radius ** 3
def show_info(self) -> None:
print(f'Площадь поверхности {self.title} = {self.area()}\n'
f'Объем {self.title} = {self.volume()}\n')
class Tetrahedron(Shape):
title = 'Тетраэдр'
def __init__(self, side1: float):
check_value([side1])
self.side = Triangle(side1, side1, side1)
def area(self) -> float:
""" Площадь поверхности тетраэдра """
return self.side.area() * 4
def height(self) -> float:
return (self.side.side1 * sqrt(6)) / 3
def show_info(self) -> None:
print(f'Площадь поверхности {self.title}а = {self.area()}\n'
f'Высота {self.title}а = {self.height()}\n')
class Cone(Shape):
title = "Конус"
def __init__(self, height: float, radius: float, forming: float):
""" Инициализация значений
height - высота конуса
radius - радиус основания конуса
forming - образующая конуса"""
check_value([height, radius, forming])
self.height = height
self.radius = radius
self.forming = forming
def area(self) -> float:
""" Площадь поверхности конуса """
return pi * self.radius * self.forming + pi * self.radius ** 2
def volume(self) -> float:
return 1 / 3 * pi * self.radius ** 2 * self.height
def show_info(self) -> None:
print(f'Площадь поверхности {self.title}а = {self.area()}\n'
f'Объем {self.title}а = {self.volume()}\n')