From 4b4f95af815f6eb54f13a66211d906439b72615e Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 10 Mar 2023 17:01:44 -0500 Subject: [PATCH] cross product --- include/blt/math/vectors.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index a20f90c..a2fc0c0 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -133,6 +133,14 @@ namespace blt { dot += left[i] * right[i]; return dot; } + + static inline vec cross(const vec& left, const vec& right) { + // cross is only defined on vectors of size 3. 2D could be implemented, which is a TODO + static_assert(size == 3); + return {left.y() * right.z() - left.z() * right.y(), + left.z() * right.x() - left.x() * right.z(), + left.x() * right.y() - left.y() * right.x()}; + } }; template