Advertisement
CosmicFox33

8.15

May 24th, 2022
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. ##15. Разработать классы «точка» и «отрезок в пространстве». Члены-данные сделать закрытой частью в каждом классе. Для каждого класса
  2. ##разработать: конструктор с параметрами для инициализации, методы ввода/вывода. Разработать 2 функции сдвига отрезка в пространстве в
  3. ##заданную точку: метод класса и функцию с двумя параметрами (точка и отрезок).
  4.  
  5. class Point():
  6.     def __init__(self, x, y, z):
  7.         self.__x = x
  8.         self.__y = y
  9.         self.__z = z
  10.  
  11.     def p_input(self):
  12.         self.__x = float(input())
  13.         self.__y = float(input())
  14.         self.__z = float(input())
  15.    
  16.    
  17.    
  18.     def p_output(self):
  19.         print("(", self.__x, ",", self.__y, ",", self.__z, ")", sep="")
  20.  
  21. class Line():
  22.     def __init__(self, x1, y1, z1, x2, y2, z2):
  23.         self.__p1 = Point(x1, y1, z1)
  24.         self.__p2 = Point(x2, y2, z2)
  25.    
  26.     def l_input(self):
  27.         self.__p1.p_input()
  28.         self.__p2.p_input()
  29.  
  30.     def l_output(self):
  31.         self.__p1.p_output()
  32.         self.__p2.p_output()
  33.    
  34.     def l_move(self, P):
  35.         x1 = self.__p1._Point__x
  36.         y1 = self.__p1._Point__y
  37.         z1 = self.__p1._Point__z
  38.         x2 = self.__p2._Point__x
  39.         y2 = self.__p2._Point__y
  40.         z2 = self.__p2._Point__z
  41.         x = P._Point__x
  42.         y = P._Point__y
  43.         z = P._Point__z
  44.         self.__p1 = P        
  45.         self.__p2 = Point(x2-x1+x, y2-y1+y, z2-z1+z)
  46.  
  47. def L_move(P, L):
  48.     x1 = L._Line__p1._Point__x
  49.     y1 = L._Line__p1._Point__y
  50.     z1 = L._Line__p1._Point__z
  51.     x2 = L._Line__p2._Point__x
  52.     y2 = L._Line__p2._Point__y
  53.     z2 = L._Line__p2._Point__z
  54.     x = P._Point__x
  55.     y = P._Point__y
  56.     z = P._Point__z
  57.     L._Line__p1 = P
  58.     L._Line__p2 = Point(x2-x1+x, y2-y1+y, z2-z1+z)
  59.  
  60. P = Point(0., 0., 0.)
  61. P.p_output()
  62. P.p_input()
  63. P.p_output()
  64.  
  65. L = Line(0., 0., 0., 1., 1., 1.)
  66. L.l_output()
  67. L.l_input()
  68. L.l_output()
  69.  
  70. L.l_move(P)
  71. L.l_output()
  72. L_move(Point(0., 0., 0.), L)
  73. L.l_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement