-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.py
More file actions
43 lines (24 loc) · 858 Bytes
/
Copy pathvector.py
File metadata and controls
43 lines (24 loc) · 858 Bytes
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
29
30
31
32
33
34
35
36
import math
class Vector:
def __init__(self, x=0.0, y=0.0, z=0.0):
self.x = x
self.y = y
self.z = z
def __str__(self):
return "("+str(self.x) +", "+ str(self.y) +", "+ str(self.z)+")"
@staticmethod
def dist(v1, v2):
return math.sqrt( (v1.x - v2.x)**2 + (v1.y - v2.y)**2 + (v1.z - v2.z)**2 )
def __sub__(v1, v2):
return Vector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z)
def __add__(v1, v2):
return Vector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z)
def len(self):
return math.sqrt(self.x**2 + self.y**2 + self.z**2)
def __mul__(v, n):
return Vector(v.x * n, v.y * n, v.z * n)
def __div__(v, n):
return Vector(v.x / n, v.y / n, v.z / n)
@staticmethod
def dotProduct(v1, v2):
return (v1.x*v2.x)+(v1.y*v2.y)+(v1.z*v2.z)