Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Guard for angleBetweenVectors function to ensure it doesn't return NaN

Oleg Kalachevd3e72911975d
diff --git a/flix/vector.h b/flix/vector.h
index 5b2df3f..02779af 100644
--- a/flix/vector.h
+++ b/flix/vector.h
@@ -79,7 +79,7 @@ public:
static float angleBetweenVectors(const Vector& a, const Vector& b)
{
- return acos(dot(a, b) / (a.norm() * b.norm()));
+ return acos(constrain(dot(a, b) / (a.norm() * b.norm()), -1, 1));
}
static Vector angularRatesBetweenVectors(const Vector& u, const Vector& v)