2002-10-02 15:27:49 +00:00
|
|
|
// ATCutils.hxx - Utility functions for the ATC / AI subsytem
|
|
|
|
//
|
|
|
|
// Written by David Luff, started March 2002.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-04-04 20:50:05 +00:00
|
|
|
|
2003-03-05 21:34:58 +00:00
|
|
|
#include <Airports/simple.hxx>
|
2003-03-11 13:25:14 +00:00
|
|
|
#include <Airports/runways.hxx>
|
2003-03-05 21:34:58 +00:00
|
|
|
|
2002-04-04 20:50:05 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <simgear/math/point3d.hxx>
|
2002-10-02 15:27:49 +00:00
|
|
|
#include <string>
|
|
|
|
SG_USING_STD(string);
|
|
|
|
|
|
|
|
// These are defined here because I had a problem with SG_DEGREES_TO_RADIANS
|
|
|
|
#define DCL_PI 3.1415926535f
|
|
|
|
#define DCL_DEGREES_TO_RADIANS (DCL_PI/180.0)
|
|
|
|
#define DCL_RADIANS_TO_DEGREES (180.0/DCL_PI)
|
|
|
|
|
|
|
|
/*******************************
|
|
|
|
*
|
|
|
|
* Communication functions
|
|
|
|
*
|
|
|
|
********************************/
|
|
|
|
|
2002-12-04 20:05:30 +00:00
|
|
|
// Convert any number to spoken digits
|
2005-10-25 08:57:33 +00:00
|
|
|
string ConvertNumToSpokenDigits(const string &n);
|
2002-12-04 20:05:30 +00:00
|
|
|
|
2003-09-19 16:48:27 +00:00
|
|
|
// Convert an integer to spoken digits
|
|
|
|
string ConvertNumToSpokenDigits(int n);
|
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
// Convert a 2 digit rwy number to a spoken-style string
|
2002-12-04 20:05:30 +00:00
|
|
|
string ConvertRwyNumToSpokenString(int n);
|
2002-10-02 15:27:49 +00:00
|
|
|
|
2003-03-05 21:34:58 +00:00
|
|
|
// Convert rwy number string to a spoken-style string
|
|
|
|
// eg "05L" to "zero five left"
|
2005-10-25 08:57:33 +00:00
|
|
|
// Assumes we get a two-digit string optionally appended with R, L, or C
|
2003-03-05 21:34:58 +00:00
|
|
|
// eg 01 07L 29R 36
|
|
|
|
// Anything else is not guaranteed to be handled correctly!
|
2005-10-25 08:57:33 +00:00
|
|
|
string ConvertRwyNumToSpokenString(const string &s);
|
2003-03-05 21:34:58 +00:00
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
// Return the phonetic letter of a letter represented as an integer 1->26
|
|
|
|
string GetPhoneticIdent(int i);
|
|
|
|
|
2004-01-23 17:18:24 +00:00
|
|
|
// Return the phonetic letter of a character in the range a-z or A-Z.
|
|
|
|
// Currently always returns prefixed by lowercase.
|
|
|
|
string GetPhoneticIdent(char c);
|
|
|
|
|
|
|
|
// Get the compass direction associated with a heading in degrees
|
|
|
|
// Currently returns 8 direction resolution (N, NE, E etc...)
|
|
|
|
// Might be modified in future to return 4, 8 or 16 resolution but defaulting to 8.
|
|
|
|
string GetCompassDirection(double h);
|
2002-10-02 15:27:49 +00:00
|
|
|
|
|
|
|
/*******************************
|
|
|
|
*
|
|
|
|
* Positional functions
|
|
|
|
*
|
|
|
|
********************************/
|
2002-04-04 20:50:05 +00:00
|
|
|
|
2003-03-10 13:40:10 +00:00
|
|
|
// Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
|
2005-10-25 13:49:55 +00:00
|
|
|
double dclGetHorizontalSeparation(const Point3D& pos1, const Point3D& pos2);
|
2002-04-04 20:50:05 +00:00
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
// Given a point and a line, get the HORIZONTAL shortest distance from the point to a point on the line.
|
|
|
|
// Expects to be fed orthogonal co-ordinates, NOT lat & lon !
|
|
|
|
double dclGetLinePointSeparation(double px, double py, double x1, double y1, double x2, double y2);
|
|
|
|
|
2002-04-04 20:50:05 +00:00
|
|
|
// Given a position (lat/lon/elev), heading, vertical angle, and distance, calculate the new position.
|
|
|
|
// Assumes that the ground is not hit!!! Expects heading and angle in degrees, distance in meters.
|
2005-10-25 13:49:55 +00:00
|
|
|
Point3D dclUpdatePosition(const Point3D& pos, double heading, double angle, double distance);
|
2002-12-04 20:05:30 +00:00
|
|
|
|
|
|
|
// Get a heading from one lat/lon to another (in degrees)
|
2005-10-25 13:49:55 +00:00
|
|
|
double GetHeadingFromTo(const Point3D& A, const Point3D& B);
|
2002-12-04 20:05:30 +00:00
|
|
|
|
|
|
|
// Given a heading (in degrees), bound it from 0 -> 360
|
|
|
|
void dclBoundHeading(double &hdg);
|
2003-03-05 21:34:58 +00:00
|
|
|
|
2003-04-15 10:37:58 +00:00
|
|
|
// 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);
|
|
|
|
|
2003-03-11 13:25:14 +00:00
|
|
|
/****************
|
|
|
|
*
|
2003-03-20 11:50:34 +00:00
|
|
|
* Runways
|
2003-03-11 13:25:14 +00:00
|
|
|
*
|
|
|
|
****************/
|
|
|
|
|
|
|
|
// Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
|
2005-10-25 13:49:55 +00:00
|
|
|
bool OnRunway(const Point3D& pt, const FGRunway& rwy);
|
2003-03-20 11:50:34 +00:00
|
|
|
|