4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "OS/Args.hpp"
25 #include "Geo/GeoPoint.hpp"
26 #include "Geo/Math.hpp"
31 AppendArc(std::vector
<GeoPoint
> &points
, GeoPoint center
,
32 fixed radius
, fixed _step
)
34 Angle start
= Angle::Zero();
35 Angle end
= Angle::HalfCircle();
37 // 5 or -5, depending on direction
38 const Angle step
= Angle::Degrees(_step
);
40 // Add first polygon point
41 points
.push_back(FindLatitudeLongitude(center
, start
, radius
));
43 // Add intermediate polygon points
44 while ((end
- start
).AbsoluteDegrees() > _step
* 3 / 2) {
45 start
= (start
+ step
).AsBearing();
46 points
.push_back(FindLatitudeLongitude(center
, start
, radius
));
49 // Add last polygon point
50 points
.push_back(FindLatitudeLongitude(center
, end
, radius
));
54 TestApproximation(fixed radius
, fixed step
)
56 GeoPoint
center(Angle::Degrees(7), Angle::Degrees(51));
58 std::vector
<GeoPoint
> points
;
59 AppendArc(points
, center
, radius
, step
);
61 printf("Number of points: %u\n\n", (unsigned)points
.size());
63 fixed max_error
= fixed(0);
65 for (auto it
= points
.begin(), it_last
= it
++, it_end
= points
.end();
66 it
!= it_end
; it_last
= it
++) {
67 for (fixed x
= fixed(0); x
< fixed(1); x
+= fixed(0.1)) {
68 GeoPoint test_point
= (*it_last
).Interpolate(*it
, x
);
69 fixed distance
= center
.Distance(test_point
);
70 fixed error
= fabs(radius
- distance
);
71 if (error
> max_error
)
76 printf("Max. Error: %f m\n", (double)max_error
);
79 int main(int argc
, char **argv
)
81 Args
args(argc
, argv
, "RADIUS [DEGREE STEPWIDTH = 5]");
83 fixed radius
= fixed(args
.ExpectNextInt());
84 fixed step
= fixed(args
.IsEmpty() ? 5 : args
.ExpectNextDouble());
86 printf("Airspace Arc Approximation\n\nRadius: %.0f m\nDegree Stepwith: %f deg\n\n",
87 (double)radius
, (double)step
);
89 TestApproximation(radius
, step
);