Advertisement
nq1s788

геометрия шаблон

Nov 12th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from math import *
  2.  
  3.  
  4. class vector:
  5.     def __init__(self, x, y):
  6.         self.x = x
  7.         self.y = y
  8.  
  9.     def vector_from_dots(self, a, b):
  10.         return vector(b.x - a.x, b.y - a.y)
  11.  
  12.     def __add__(self, other):
  13.         return vector(self.x + other.x, self.y + other.y)
  14.  
  15.     def __sub__(self, other):
  16.         return vector(self.x - other.x, self.y - other.y)
  17.  
  18.     def __mul__(self, other): #скалярное произведение
  19.         return self.x * other.x + self.y * other.y
  20.  
  21.     def __xor__(self, other): #векторное произведение
  22.         return self.x * other.y - self.y * other.x
  23.  
  24.     def len(self):
  25.         return sqrt(self.x * self.x + self.y * self.y)
  26.  
  27.  
  28. a = vector(1, 2)
  29. b = vector(4, 5)
  30. c = a + b
  31. d = a - b
  32. print(a.x, a.y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement