From 49434e3085977698e2cb5879cc709f7148c914c7 Mon Sep 17 00:00:00 2001 From: daveluff Date: Tue, 15 Apr 2003 10:37:58 +0000 Subject: [PATCH] Fixed some stuff in runway number to spoken string function, and added Alexander's function to get the minimum angular difference between two headings from approach to ATCutils --- src/ATC/ATCutils.cxx | 28 ++++++++++++++++++++++++++-- src/ATC/ATCutils.hxx | 4 ++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/ATC/ATCutils.cxx b/src/ATC/ATCutils.cxx index 1c182357e..20a781902 100644 --- a/src/ATC/ATCutils.cxx +++ b/src/ATC/ATCutils.cxx @@ -80,7 +80,7 @@ string ConvertRwyNumToSpokenString(int n) { return(str); } -// Assumes we get a two-digit string optionally appended with R or L +// Assumes we get a two-digit string optionally appended with L, R or C // eg 01 07L 29R 36 // Anything else is not guaranteed to be handled correctly! string ConvertRwyNumToSpokenString(string s) { @@ -88,7 +88,16 @@ string ConvertRwyNumToSpokenString(string s) { return(ConvertRwyNumToSpokenString(atoi(s.c_str()))); } else { string r = ConvertRwyNumToSpokenString(atoi(s.substr(0,2).c_str())); - return(r += (s.substr(2,1) == "L" ? " left" : " right")); // Warning - not much error checking there! + if(s.substr(2,1) == "L") { + r += " left"; + } else if(s.substr(2,1) == "R") { + r += " right"; + } else if(s.substr(2,1) == "C") { + r += " center"; + } else { + SG_LOG(SG_ATC, SG_WARN, "WARNING: Unknown suffix " << s.substr(2,1) << " from runway ID " << s << " in ConvertRwyNumToSpokenString(...)"); + } + return(r); } } @@ -128,6 +137,8 @@ string GetPhoneticIdent(int i) { return("Error"); } +//================================================================================================================ + // Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters) double dclGetHorizontalSeparation(Point3D pos1, Point3D pos2) { double x; //East-West separation @@ -238,6 +249,19 @@ void dclBoundHeading(double &hdg) { } } +// smallest difference between two angles in degrees +// difference is negative if a1 > a2 and positive if a2 > a1 +double GetAngleDiff_deg( const double &a1, const double &a2) { + + double a3 = a2 - a1; + while (a3 < 180.0) a3 += 360.0; + while (a3 > 180.0) a3 -= 360.0; + + return a3; +} + +//================================================================================================================ + // Airport stuff. The next two functions are straight copies of their fg.... equivalents // in fg_init.cxx, and are just here temporarily until some rationalisation occurs. // find basic airport location info from airport database diff --git a/src/ATC/ATCutils.hxx b/src/ATC/ATCutils.hxx index b48739047..420b61632 100644 --- a/src/ATC/ATCutils.hxx +++ b/src/ATC/ATCutils.hxx @@ -77,6 +77,10 @@ double GetHeadingFromTo(Point3D A, Point3D B); // Given a heading (in degrees), bound it from 0 -> 360 void dclBoundHeading(double &hdg); +// smallest difference between two angles in degrees +// difference is negative if a1 > a2 and positive if a2 > a1 +double GetAngleDiff_deg( const double &a1, const double &a2); + /******************************* * -- 2.39.5