From 263560f48cc4ae578380b21d54cad7995b55f2f2 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sat, 3 Jul 2021 17:29:35 +0200 Subject: [PATCH] Add vector.rotate3 --- vector.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vector.lua b/vector.lua index 1c903ce..a25312d 100644 --- a/vector.lua +++ b/vector.lua @@ -190,6 +190,14 @@ function angle(v, w) return math.acos(dot(v, w) / length(v) / length(w)) end +-- Uses Rodrigues' rotation formula +function rotate3(v, axis, angle) + local cos = math.cos(angle) + return multiply_scalar(v, cos) + + multiply_scalar(cross3(axis, v), math.sin(angle)) + + multiply_scalar(axis, dot(axis, v) * (1 - cos)) +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