-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector3.py
More file actions
108 lines (81 loc) · 2.58 KB
/
Copy pathVector3.py
File metadata and controls
108 lines (81 loc) · 2.58 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import math
class Vector3():
def __init__(self):
self.x = 0
self.y = 0
self.z = 0
#
###
def cross(self, other):
crossProduct = Vector3()
crossProduct.x = (self.y * other.z) - (self.z * other.y)
crossProduct.y = - ((self.x * other.z) - (self.z * other.x))
crossProduct.z = (self.x * other.y) - (self.y * other.x)
return crossProduct
###
def dot(self, other):
return (self.x * other.x) + (self.y * other.y) + (self.z * other.z)
###
def magnitudeSquared(self):
return (self.x * self.x) + (self.y * self.y) + (self.z * self.z)
###
def magnitude(self):
return math.sqrt(self.magnitudeSquared())
###
# def amountProjectedOnto(self, projectOnto):
# if (projectOnto.magnitudeSquared() == 0):
# return 0
# else:
# return (((self.x * projectOnto.x) + (self.y * projectOnto.y)) / projectOnto.magnitude())
# #
# ###
# def projectedOnto(self, projectOnto):
# if ((self.x == 0 and self.y == 0) or (projectOnto.x == 0 and projectOnto.y == 0)):
# return Vector3()
# else:
# projectedVector = Vector3()
# AdotB = self.dot(projectOnto)
# BdotB = projectOnto.dot(projectOnto)
# dotRatio = AdotB / BdotB
# projectedVector.x = projectOnto.x * dotRatio
# projectedVector.y = projectOnto.y * dotRatio
# return projectedVector
# #
# ###
def subtract(self, vector):
result = Vector3()
result.x = self.x - vector.x
result.y = self.y - vector.y
result.z = self.z - vector.z
return result
###
def add(self, vector):
result = Vector3()
result.x = self.x + vector.x
result.y = self.y + vector.y
result.z = self.z + vector.z
return result
###
def multiply(self, scalar):
result = Vector3()
result.x = self.x * scalar
result.y = self.y * scalar
result.z = self.z * scalar
return result
###
def divide(self, scalar):
result = Vector3()
result.x = self.x / scalar
result.y = self.y / scalar
result.z = self.z / scalar
return result
###
def normalized(self):
normalized = Vector3()
magnitude = self.magnitude()
normalized.x = self.x / magnitude
normalized.y = self.y / magnitude
normalized.z = self.z / magnitude
return normalized
###
###