1 // runways.cxx -- a simple class to manage airport runway info
3 // Written by Curtis Olson, started August 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
28 #include <cmath> // fabs()
29 #include <cstdio> // sprintf()
30 #include <cstdlib> // atoi()
32 #include <simgear/compiler.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <Main/fg_props.hxx>
39 #include "runways.hxx"
45 static FGPositioned::Type runwayTypeFromNumber(const std::string& aRwyNo)
47 return (aRwyNo[0] == 'x') ? FGPositioned::TAXIWAY : FGPositioned::RUNWAY;
50 static std::string cleanRunwayNo(const std::string& aRwyNo)
52 if (aRwyNo[0] == 'x') {
53 return std::string(); // no ident for taxiways
56 string result(aRwyNo);
57 // canonicalise runway ident
58 if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
59 result = "0" + aRwyNo;
62 // trim off trailing garbage
63 if (result.size() > 2) {
64 char suffix = toupper(result[2]);
66 result = result.substr(0, 2);
73 FGRunway::FGRunway(FGAirport* aAirport, const string& rwy_no,
74 const double longitude, const double latitude,
75 const double heading, const double length,
77 const double displ_thresh,
79 const int surface_code,
81 FGPositioned(runwayTypeFromNumber(rwy_no), cleanRunwayNo(rwy_no), latitude, longitude, 0.0),
83 _reciprocal(reciprocal)
92 _displ_thresh = displ_thresh;
95 _surface_code = surface_code;
98 string FGRunway::reverseIdent(const string& aRunwayIdent)
100 // Helipads don't have a seperate number per end
101 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
105 std::string ident(aRunwayIdent);
108 int rn = atoi(ident.substr(0,2).c_str());
114 sprintf(buf, "%02i", rn);
115 if(ident.size() == 3) {
116 char suffix = toupper(ident[2]);
119 } else if (suffix == 'R') {
122 // something else, just copy
132 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
135 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
137 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
140 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
143 bool FGRunway::isTaxiway() const
145 return (type() == TAXIWAY);
148 SGGeod FGRunway::threshold() const
150 return pointOnCenterline(0.0);
153 SGGeod FGRunway::reverseThreshold() const
155 return pointOnCenterline(lengthM());
158 SGGeod FGRunway::displacedThreshold() const
160 return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
163 SGGeod FGRunway::pointOnCenterline(double aOffset) const
167 double halfLengthMetres = lengthM() * 0.5;
169 SGGeodesy::direct(mPosition, _heading,
170 aOffset - halfLengthMetres,