Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use vector.dot and vector.cross in vector.angle
  • Loading branch information
HybridDog authored and sfan5 committed Jul 16, 2019
1 parent 71db715 commit 4122969
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions builtin/common/vector.lua
Expand Up @@ -71,11 +71,9 @@ function vector.direction(pos1, pos2)
end

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

Expand Down

0 comments on commit 4122969

Please sign in to comment.