From 71db715ba56369c67aa3187315601e2ae25d719a Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sat, 13 Jul 2019 13:46:44 +0200 Subject: Add vector.dot and vector.cross Mostly copied from MarkuBu's code --- builtin/common/vector.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'builtin/common/vector.lua') diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index 9a53409fa..782c137d6 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -79,6 +79,18 @@ function vector.angle(a, b) return math.atan2(crossplen, dotp) end +function vector.dot(a, b) + return a.x * b.x + a.y * b.y + a.z * b.z +end + +function vector.cross(a, b) + return { + x = a.y * b.z - a.z * b.y, + y = a.z * b.x - a.x * b.z, + z = a.x * b.y - a.y * b.x + } +end + function vector.add(a, b) if type(b) == "table" then return {x = a.x + b.x, -- cgit v1.2.3