]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ATCutils.hxx
c47c3469a0f5e9220b40314d75362606cf5688e0
[flightgear.git] / src / ATCDCL / ATCutils.hxx
1 // ATCutils.hxx - Utility functions for the ATC / AI subsytem
2 //
3 // Written by David Luff, started March 2002.
4 //
5 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #include <Airports/simple.hxx>
22 #include <Airports/runways.hxx>
23
24 #include <math.h>
25 #include <simgear/math/point3d.hxx>
26 #include <string>
27 using std::string;
28
29 // These are defined here because I had a problem with SG_DEGREES_TO_RADIANS
30 #define DCL_PI  3.1415926535f
31 #define DCL_DEGREES_TO_RADIANS  (DCL_PI/180.0)
32 #define DCL_RADIANS_TO_DEGREES  (180.0/DCL_PI)
33
34 /*******************************
35 *
36 *  Communication functions
37 *
38 ********************************/
39
40 // Convert any number to spoken digits
41 string ConvertNumToSpokenDigits(const string &n);
42
43 // Convert an integer to spoken digits
44 string ConvertNumToSpokenDigits(int n);
45
46 // Convert a 2 digit rwy number to a spoken-style string
47 string ConvertRwyNumToSpokenString(int n);
48
49 // Convert rwy number string to a spoken-style string
50 // eg "05L" to "zero five left"
51 // Assumes we get a two-digit string optionally appended with R, L, or C
52 // eg 01 07L 29R 36
53 // Anything else is not guaranteed to be handled correctly!
54 string ConvertRwyNumToSpokenString(const string &s);
55
56 // Return the phonetic letter of a letter represented as an integer 1->26
57 string GetPhoneticIdent(int i);
58
59 // Return the phonetic letter of a character in the range a-z or A-Z.
60 // Currently always returns prefixed by lowercase.
61 string GetPhoneticIdent(char c);
62
63 // Get the compass direction associated with a heading in degrees
64 // Currently returns 8 direction resolution (N, NE, E etc...)
65 // Might be modified in future to return 4, 8 or 16 resolution but defaulting to 8. 
66 string GetCompassDirection(double h);
67
68 /*******************************
69 *
70 *  Positional functions
71 *
72 ********************************/
73
74 // Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
75 double dclGetHorizontalSeparation(const Point3D& pos1, const Point3D& pos2);
76
77 // Given a point and a line, get the HORIZONTAL shortest distance from the point to a point on the line.
78 // Expects to be fed orthogonal co-ordinates, NOT lat & lon !
79 double dclGetLinePointSeparation(double px, double py, double x1, double y1, double x2, double y2);
80
81 // Given a position (lat/lon/elev), heading, vertical angle, and distance, calculate the new position.
82 // Assumes that the ground is not hit!!!  Expects heading and angle in degrees, distance in meters.
83 Point3D dclUpdatePosition(const Point3D& pos, double heading, double angle, double distance);
84
85 // Get a heading from one lat/lon to another (in degrees)
86 double GetHeadingFromTo(const Point3D& A, const Point3D& B);
87
88 // Given a heading (in degrees), bound it from 0 -> 360
89 void dclBoundHeading(double &hdg);
90
91 // smallest difference between two angles in degrees
92 // difference is negative if a1 > a2 and positive if a2 > a1
93 double GetAngleDiff_deg( const double &a1, const double &a2);
94
95 /****************
96 *
97 *   Runways
98 *
99 ****************/
100
101 // Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
102 bool OnRunway(const Point3D& pt, const FGRunwayBase* rwy);
103