From be3d2be9d3244b35ab6b76fe1cf9ac7033f5758c Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Tue, 21 May 2024 10:50:47 +0300 Subject: [PATCH] Fix Vector::angularRatesBetweenVectors return NaNs on opposite vectors --- flix/vector.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flix/vector.h b/flix/vector.h index c1433e1..b096a5e 100644 --- a/flix/vector.h +++ b/flix/vector.h @@ -80,6 +80,10 @@ public: static Vector angularRatesBetweenVectors(const Vector& a, const Vector& b) { Vector direction = cross(a, b); + if (direction.zero()) { + // vectors are opposite, return any perpendicular vector + return cross(a, Vector(1, 0, 0)); + } direction.normalize(); float angle = angleBetweenVectors(a, b); return direction * angle;