Use vector.dot and vector.cross in vector.angle

master
HybridDog 2019-07-14 11:45:55 +02:00 committed by sfan5
parent 71db715ba5
commit 41229696be
1 changed files with 3 additions and 5 deletions

View File

@ -71,11 +71,9 @@ function vector.direction(pos1, pos2)
end end
function vector.angle(a, b) function vector.angle(a, b)
local dotp = a.x * b.x + a.y * b.y + a.z * b.z local dotp = vector.dot(a, b)
local cpx = a.y * b.z - a.z * b.y local cp = vector.cross(a, b)
local cpy = a.z * b.x - a.x * b.z local crossplen = vector.length(cp)
local cpz = a.x * b.y - a.y * b.x
local crossplen = math.sqrt(cpx ^ 2 + cpy ^ 2 + cpz ^ 2)
return math.atan2(crossplen, dotp) return math.atan2(crossplen, dotp)
end end