From f0f48c0fb4b04ebed449a03d7a4507588eb4dedd Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Wed, 24 Mar 2021 10:36:28 +0100 Subject: [PATCH] Add vector.angle --- vector.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vector.lua b/vector.lua index 4446718..0c50e60 100644 --- a/vector.lua +++ b/vector.lua @@ -175,6 +175,13 @@ function dot(v, other_v) return sum end +--+ Angle between two vectors +--> Signed angle in radians +function angle(v, other_v) + -- Based on dot(v, w) = |v| * |w| * cos(x) + return math.acos(dot(v, other_v) / length(v) / length(other_v)) +end + function box_box_collision(diff, box, other_box) for index, diff in pairs(diff) do if box[index] + diff > other_box[index + 3] or other_box[index] > box[index + 3] + diff then