From 3743a74c6e4ae1a1f54f9be1296639f9dab2502b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bor=20Gro=C5=A1elj=20Simi=C4=87?= Date: Thu, 13 Jan 2022 01:49:11 +0100 Subject: [PATCH] implement cross product --- vector.ha | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vector.ha b/vector.ha index cd9e313..6dcc5ba 100644 --- a/vector.ha +++ b/vector.ha @@ -26,6 +26,12 @@ export fn sum(v1: vector, v2: vector) vector = vector { export fn diff(v1: vector, v2: vector) vector = sum(v1, neg(v2)); +export fn cross(v1: vector, v2: vector) vector = vector { + x = v1.y * v2.z - v1.z * v2.y, + y = v1.z * v2.x - v1.x * v2.z, + z = v1.x * v2.y - v1.y * v2.x, +}; + export fn dot(v1: vector, v2: vector) f64 = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; export fn length(v: vector) f64 = math::sqrtf64(dot(v, v)); -- 2.45.2