-
Notifications
You must be signed in to change notification settings - Fork 0
/
Route.cpp
47 lines (35 loc) · 936 Bytes
/
Route.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Route.h"
#include "Airport.h"
#include <cmath>
// define pi 3.14159265358979323846
long double toRad(const double degree) {
double d1 = (M_PI) / 180;
return (d1 * degree);
}
Route::Route() {
}
Route::Route(const Airport & a1, const Airport & a2) {
source = a1;
destination = a2;
calcDist();
}
void Route::calcDist() {
double lat1 = toRad(source.getLatitude());
double long1 = toRad(source.getLongitude());
double lat2 = toRad(destination.getLatitude());
double long2 = toRad(destination.getLongitude());
double lon = long2 - long1;
double lat = lat2 - lat1;
dist = sin(lat / 2) * sin(lat / 2) + cos(lat1) * cos(lat2) * sin(lon / 2) * sin(lon / 2);
dist = 2 * asin(sqrt(dist));
dist = (6371.0 * dist);
}
double Route::getDist() {
return dist;
}
Airport Route::getSource() {
return source;
}
Airport Route::getDestination() {
return destination;
}