From 940846e42050c1c908008705c34e1604c6096ca1 Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Tue, 21 Nov 2023 11:26:52 +0100 Subject: [PATCH] [vec] Add 2D cross product Add 2D cross product (returns a scalar value). For consistency with the rest of the API, the 3D cross product has been renamed to cross3(). --- vec.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vec.lua b/vec.lua index 78af442..a78f6b3 100644 --- a/vec.lua +++ b/vec.lua @@ -26,8 +26,13 @@ function vec.dot3(x1,y1,z1, x2,y2,z2) return x1*x2 + y1*y2 + z1*z2 end ---- Vector cross product. -function vec.cross(x1,y1,z1, x2,y2,z2) +--- Vector cross product in 2D, returning a scalar. +function vec.cross(x1,y1, x2,y2) + return x1*y2 - y1*x2 +end + +--- Vector cross product in 3D, returning a vector. +function vec.cross3(x1,y1,z1, x2,y2,z2) return y1*z2 - z1*y2, z1*x2 - x1*z2, x1*y2 - y1*x2