From a520145a6a74ca0bfbd00a9d76b06825ce33560f Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Wed, 30 Oct 2019 20:12:23 +0000 Subject: [PATCH] Ref T736 Radar was still wrong as the conversion assumed angles are counterclockwise The new polarPoint function is split into steps so each adjustment is clear to see. --- src/blackgui/components/radarcomponent.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/blackgui/components/radarcomponent.cpp b/src/blackgui/components/radarcomponent.cpp index a66798a76..f40c7f556 100644 --- a/src/blackgui/components/radarcomponent.cpp +++ b/src/blackgui/components/radarcomponent.cpp @@ -286,7 +286,19 @@ namespace BlackGui QPointF CRadarComponent::polarPoint(double distance, double angleRadians) { - return { -distance * qSin(angleRadians), -distance * qCos(angleRadians) }; + angleRadians = -angleRadians; // conversion assumes angles are counterclockwise + + // standard conversion from https://en.wikipedia.org/wiki/Polar_coordinate_system + QPointF p(distance * qCos(angleRadians), distance * qSin(angleRadians)); + + // conversion yields a coordinate system + // in which North=(1,0) and East=(-1,0) + // but we want North=(0,-1) and East=(0,1) + // (QGraphicsView y axis increases downwards) + qSwap(p.rx(), p.ry()); + p.setX(-p.x()); + p.setY(-p.y()); + return p; } } // namespace } // namespace