PY
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
class Vector3D:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
#adding two vectors
def __add__(self, other):
return Vector3D(self.x + other.x, self.y + other.y, self.z + other.z)
#subtracting two vectors
def __sub__(self, other):
return Vector3D(self.x - other.x, self.y - other.y, self.z - other.z)
#dot product
def dot(self, other):
return (self.x*other.x + self.y*other.y+self.z*other.z)
#cross product
def cross(self,other):
return Vector3D(self.y*other.z - self.z*other.y, self.z*other.x-self.x*other.z, self.x*other.y-self.y*other.x)
#insert your wanted vector coordinates
first = Vector3D(5, 7, 2)
second = Vector3D(3, 9, 3)
result_add = first + second
print ("Vectors added")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run