diff --git a/modules/vec3.lua b/modules/vec3.lua index ed8ea05..b466028 100644 --- a/modules/vec3.lua +++ b/modules/vec3.lua @@ -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 diff --git a/spec/vec3_spec.lua b/spec/vec3_spec.lua index 8621fee..7db88b5 100644 --- a/spec/vec3_spec.lua +++ b/spec/vec3_spec.lua @@ -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)