From afed4793cb8f7fc9b1d316e504bbfaae47aea53d Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Wed, 3 Feb 2021 12:49:23 +0100 Subject: [PATCH] Quaternion: Add conjugate and invert --- quaternion.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/quaternion.lua b/quaternion.lua index 8df2694..bae609a 100644 --- a/quaternion.lua +++ b/quaternion.lua @@ -16,6 +16,19 @@ function normalize(self) return res end +function conjugate(self) + return { + -self[1], + -self[2], + -self[3], + self[4] + } +end + +function inverse(self) + return modlib.vector.divide_scalar(conjugate(self), self[1] ^ 2 + self[2] ^ 2 + self[3] ^ 2 + self[4] ^ 2) +end + function negate(self) for key, value in pairs(self) do self[key] = -value