-
Notifications
You must be signed in to change notification settings - Fork 0
/
subway.cpp
37 lines (33 loc) · 924 Bytes
/
subway.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
#include "subway.h"
double Station::minLongitude = 200;
double Station::minLatitude = 200;
double Station::maxLongitude = 0;
double Station::maxLatitude = 0;
// 角度转弧度
double rad(double d)
{
return d * M_PI / 180;
}
// 构造函数
Station::Station(QString name, double longitude, double latitude, QList<int> linesList)
: name(name)
, longitude(longitude)
, latitude(latitude)
{
for (const int &item : linesList) {
belongLines.insert(item);
};
}
// 站点间距离
double Station::distance(Station other)
{
const double EARTH_RADIUS = 6378.137;
double radLat1 = rad(latitude);
double radLat2 = rad(other.latitude);
double a = radLat1 - radLat2;
double b = rad(longitude) - rad(other.longitude);
double dis = 2
* asin(sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2)));
dis *= EARTH_RADIUS;
return dis;
}