Skip to content

Commit

Permalink
implement ES internal coordinate calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
KingfuChan committed Jul 17, 2023
1 parent 4cf9e5c commit ae38a51
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
35 changes: 25 additions & 10 deletions RDFPlugin/CRDFPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ using namespace std;
#define SETTING_DRAW_CONTROLLERS "DrawControllers"

const double pi = 3.141592653589793;
const double EarthRadius = 6371.393 / 1.852; // nautical miles, need tuning in accordance to ES internal setting
const double EarthRadius = 3438.0; // nautical miles, referred to internal CEuroScopeCoord
constexpr double GEOM_RAD_FROM_DEG(double deg) { return deg * pi / 180.0; };
constexpr double GEOM_DEG_FROM_RAD(double rad) { return rad / pi * 180.0; };

CRDFPlugin::CRDFPlugin()
: EuroScopePlugIn::CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE,
Expand Down Expand Up @@ -315,15 +317,7 @@ void CRDFPlugin::ProcessMessageQueue(void)
if (offset > 0) { // add random offset
double distance = abs(disDistance(rdGenerator)) / 3.0 * offset;
double bearing = disBearing(rdGenerator);
double rLat1 = pos.m_Latitude / 180.0 * pi;
double rLon1 = pos.m_Longitude / 180.0 * pi;
double rDistance = distance / EarthRadius;
double rBearing = bearing / 180.0 * pi;
double rLat2 = asin(sin(rLat1) * cos(rDistance) + cos(rLat1) * sin(rDistance) * cos(rBearing));
double rLon2 = abs(cos(rLat1)) < 0.000001 ? rLon1 : \
rLon1 + atan2(sin(rBearing) * sin(rDistance) * cos(rLat1), cos(rDistance) - sin(rLat1) * sin(rLat2));
posnew.m_Latitude = rLat2 / pi * 180.0;
posnew.m_Longitude = rLon2 / pi * 180.0;
AddOffset(posnew, bearing, distance);
#ifdef _DEBUG
double _dis = pos.DistanceTo(posnew);
double _dir = pos.DirectionTo(posnew);
Expand All @@ -345,6 +339,27 @@ void CRDFPlugin::ProcessMessageQueue(void)
}
}

void CRDFPlugin::AddOffset(CPosition& position, double heading, double distance)
{
// from ES internal void CEuroScopeCoord :: Move ( double heading, double distance )
if (distance < 0.000001)
return;

double m_Lat = position.m_Latitude;
double m_Lon = position.m_Longitude;

double distancePerR = distance / EarthRadius;
double cosDistancePerR = cos(distancePerR);
double sinDistnacePerR = sin(distancePerR);

double fi2 = asin(sin(GEOM_RAD_FROM_DEG(m_Lat)) * cosDistancePerR + cos(GEOM_RAD_FROM_DEG(m_Lat)) * sinDistnacePerR * cos(GEOM_RAD_FROM_DEG(heading)));
double lambda2 = GEOM_RAD_FROM_DEG(m_Lon) + atan2(sin(GEOM_RAD_FROM_DEG(heading)) * sinDistnacePerR * cos(GEOM_RAD_FROM_DEG(m_Lat)),
cosDistancePerR - sin(GEOM_RAD_FROM_DEG(m_Lat)) * sin(fi2));

position.m_Latitude = GEOM_DEG_FROM_RAD(fi2);
position.m_Longitude = GEOM_DEG_FROM_RAD(lambda2);
}

void CRDFPlugin::VectorAudioHTTPLoop(void)
{
threadRunning = true;
Expand Down
4 changes: 3 additions & 1 deletion RDFPlugin/CRDFPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace std;
using namespace EuroScopePlugIn;

const string MY_PLUGIN_NAME = "RDF Plugin for Euroscope";
const string MY_PLUGIN_VERSION = "1.3.3";
const string MY_PLUGIN_VERSION = "1.3.4";
const string MY_PLUGIN_DEVELOPER = "Kingfu Chan, Claus Hemberg Joergensen";
const string MY_PLUGIN_COPYRIGHT = "Free to be distributed as source code";

Expand Down Expand Up @@ -99,5 +99,7 @@ class CRDFPlugin : public EuroScopePlugIn::CPlugIn
COLORREF rdfRGB, rdfConcurrentTransmissionRGB;
int circleThreshold;

void AddOffset(CPosition& position, double heading, double distance);

};

22 changes: 21 additions & 1 deletion RDFPlugin/CRDFScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,27 @@ void CRDFScreen::OnRefresh(HDC hDC, int Phase)
}
if (drawR >= (double)rdfPlugin->circleThreshold) {
// draw circle
Ellipse(hDC, pPos.x - round(drawR), pPos.y - round(drawR), pPos.x + round(drawR), pPos.y + round(drawR));
if (rdfPlugin->circleThreshold >= 0) {
// using position as boundary xy
CPosition pl = callsignPos.second.position;
rdfPlugin->AddOffset(pl, 270, callsignPos.second.radius);
CPosition pt = callsignPos.second.position;
rdfPlugin->AddOffset(pt, 0, callsignPos.second.radius);
CPosition pr = callsignPos.second.position;
rdfPlugin->AddOffset(pr, 90, callsignPos.second.radius);
CPosition pb = callsignPos.second.position;
rdfPlugin->AddOffset(pb, 180, callsignPos.second.radius);
Ellipse(hDC,
ConvertCoordFromPositionToPixel(pl).x,
ConvertCoordFromPositionToPixel(pt).y,
ConvertCoordFromPositionToPixel(pr).x,
ConvertCoordFromPositionToPixel(pb).y
);
}
else {
// using pixel as boundary xy
Ellipse(hDC, pPos.x - round(drawR), pPos.y - round(drawR), pPos.x + round(drawR), pPos.y + round(drawR));
}
continue;
}
}
Expand Down
Binary file modified RDFPlugin/RDFPlugin.aps
Binary file not shown.
Binary file modified RDFPlugin/RDFPlugin.rc
Binary file not shown.
3 changes: 3 additions & 0 deletions RDFPlugin/RDFPlugin.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<LocalDebuggerWorkingDirectory>\\Mac\Home\Documents\EuroScope</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>

0 comments on commit ae38a51

Please sign in to comment.