Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- class vector:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def vector_from_dots(self, a, b):
- return vector(b.x - a.x, b.y - a.y)
- def __add__(self, other):
- return vector(self.x + other.x, self.y + other.y)
- def __sub__(self, other):
- return vector(self.x - other.x, self.y - other.y)
- def __mul__(self, other): #скалярное произведение
- return self.x * other.x + self.y * other.y
- def __xor__(self, other): #векторное произведение
- return self.x * other.y - self.y * other.x
- def len(self):
- return sqrt(self.x * self.x + self.y * self.y)
- a = vector(1, 2)
- b = vector(4, 5)
- c = a + b
- d = a - b
- print(a.x, a.y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement