From 99e4515358dc1f8629520f62ee8f68d4c1ae24c5 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Fri, 24 Mar 2023 15:42:56 +0100 Subject: [PATCH] Fix: adding two vectors with nearly the same angle --- src/Polar.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Polar.cpp b/src/Polar.cpp index 7ba7ca1..5ca6055 100644 --- a/src/Polar.cpp +++ b/src/Polar.cpp @@ -34,8 +34,10 @@ Polar Polar::operator+(const Polar& v2) const { float deltaAngle = Angle::Normalize(v2.angle - this->angle); float rotation = deltaAngle < 0 ? 180 + deltaAngle : 180 - deltaAngle; - if (rotation == 180 && v2.distance > 0) - return Polar::zero; + if (rotation == 180 && v2.distance > 0) { + // angle is too small, take this angle and add the distances + return Polar(this->angle, this->distance + v2.distance); + } float newDistance = Angle::CosineRuleSide(v2.distance, this->distance, rotation);