Advertisement
otorp2

001 python vector class

Jan 12th, 2020
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. class Vector():
  2.     def __init__(self):
  3.         self.x = 0
  4.         self.y = 0
  5.  
  6.     def get_vector(self):
  7.         return [self.x, self.y]
  8.  
  9. class Point():
  10.     def __init__(self):
  11.         self.x = 0
  12.         self.y = 0
  13.        
  14.     def get_point(self):
  15.         return[self.x, self.y]
  16.    
  17.     def add_vector(self, vector):
  18.         p2 = Point()
  19.         p2.x = self.x + vector.x
  20.         p2.y = self.y + vector.y
  21.         return p2
  22.    
  23. v = Vector()
  24. v.x = 2
  25. v.y = 3
  26. p = Point()
  27. p.x = 1
  28. p.y = 0
  29. p2 = p.add_vector(v)        
  30. print(p2.get_point())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement