Skip to content

Commit 4122969

Browse files
HybridDogsfan5
authored andcommittedJul 16, 2019
Use vector.dot and vector.cross in vector.angle
1 parent 71db715 commit 4122969

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed
 

Diff for: ‎builtin/common/vector.lua

+3-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ function vector.direction(pos1, pos2)
7171
end
7272

7373
function vector.angle(a, b)
74-
local dotp = a.x * b.x + a.y * b.y + a.z * b.z
75-
local cpx = a.y * b.z - a.z * b.y
76-
local cpy = a.z * b.x - a.x * b.z
77-
local cpz = a.x * b.y - a.y * b.x
78-
local crossplen = math.sqrt(cpx ^ 2 + cpy ^ 2 + cpz ^ 2)
74+
local dotp = vector.dot(a, b)
75+
local cp = vector.cross(a, b)
76+
local crossplen = vector.length(cp)
7977
return math.atan2(crossplen, dotp)
8078
end
8179

0 commit comments

Comments
 (0)
Please sign in to comment.