Add vec3.angle_to

This commit is contained in:
xiejiangzhi 2022-04-20 19:13:08 +08:00
parent ea79f346f6
commit 02d7604b17
2 changed files with 11 additions and 0 deletions

View File

@ -318,6 +318,11 @@ function vec3.flip_z(a)
return vec3.new(a.x, a.y, -a.z)
end
function vec3.angle_to(a, b)
local v = a:normalize():dot(b:normalize())
return math.acos(v)
end
--- Return a boolean showing if a table is or is not a vec3.
-- @tparam vec3 a Vector to be tested
-- @treturn boolean is_vec3

View File

@ -224,4 +224,10 @@ describe("vec3:", function()
temp = temp:flip_z()
assert.is.equal(temp, vec3(-1, -2, -3))
end)
-- it("get two 3-vectors angle", function()
-- local a = vec3(1,2,3)
-- local b = vec3(3,2,1)
-- -- assert.is.equal(a:angle_to(b), 1)
-- end)
end)