Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Fix Vector::angularRatesBetweenVectors return NaNs on opposite vectors

Oleg Kalachevbe3d2be9d324
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;