mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:19:26 +08:00
Ref T736 Refactor CRadarComponent so the polar-to-cartesian conversion happens in one place only.
This commit is contained in:
committed by
Klaus Basan
parent
6d1f0328bf
commit
7b538a560a
@@ -133,7 +133,7 @@ namespace BlackGui
|
||||
|
||||
for (qreal angle = 0.0; angle < 359.0; angle += 30.0)
|
||||
{
|
||||
const QLineF line(0.0, 0.0, 100.0 * qCos(qDegreesToRadians(angle)), -100.0 * qSin(qDegreesToRadians(angle)));
|
||||
const QLineF line({ 0.0, 0.0 }, polarPoint(100.0, qDegreesToRadians(angle)));
|
||||
QGraphicsLineItem *li = new QGraphicsLineItem(line, &m_radials);
|
||||
li->setPen(pen);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace BlackGui
|
||||
const double bearingRad = sa.getRelativeBearing().value(CAngleUnit::rad());
|
||||
const int groundSpeedKts = sa.getGroundSpeed().valueInteger(CSpeedUnit::kts());
|
||||
|
||||
QPointF position(distanceNM * qSin(bearingRad), -distanceNM * qCos(bearingRad));
|
||||
QPointF position(polarPoint(distanceNM, bearingRad));
|
||||
|
||||
QGraphicsEllipseItem *dot = new QGraphicsEllipseItem(-2.0, -2.0, 4.0, 4.0, &m_radarTargets);
|
||||
dot->setPos(position);
|
||||
@@ -191,7 +191,7 @@ namespace BlackGui
|
||||
double headingRad = sa.getHeading().value(CAngleUnit::rad());
|
||||
QPen pen(Qt::green, 1);
|
||||
pen.setCosmetic(true);
|
||||
QGraphicsLineItem *li = new QGraphicsLineItem(QLineF(0.0, 0.0, 20.0 * qSin(headingRad), -20.0 * qCos(headingRad)), dot);
|
||||
QGraphicsLineItem *li = new QGraphicsLineItem(QLineF({ 0.0, 0.0 }, polarPoint(20.0, headingRad)), dot);
|
||||
li->setFlags(QGraphicsItem::ItemIgnoresTransformations);
|
||||
li->setPen(pen);
|
||||
}
|
||||
@@ -282,7 +282,11 @@ namespace BlackGui
|
||||
if (!myself) { return; }
|
||||
myself->refreshTargets();
|
||||
});
|
||||
}
|
||||
|
||||
QPointF CRadarComponent::polarPoint(double distance, double angleRadians)
|
||||
{
|
||||
return { distance * qSin(angleRadians), -distance * qCos(angleRadians) };
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user