-
Notifications
You must be signed in to change notification settings - Fork 0
/
vc2gps.h
135 lines (113 loc) · 3.28 KB
/
vc2gps.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef VC2GPS_H_
#define VC2GPS_H_
#include <math.h>
#define R 6371000.0
#define I1_LAT 0.697334667
#define I1_LON -1.312344093
#define I2_LAT 0.697330304
#define I2_LON -1.312308216
#define I3_LAT 0.697356969
#define I3_LON -1.312303853
#define I4_LAT 0.697361332
#define I4_LON -1.312338275
#define ABC_B 1.728132911
#define DEF_B 0.124781345
#define GHI_B 4.87628509
#define IHG_B 1.734668199
#define JKL_B 3.307306818
enum RoadIdentifier {
AB,
BC,
DE,
EF,
GH,
HI,
IH,
HG,
JK,
KL
};
struct GPS_Coord {
double lat, lon;
};
inline double inDegrees(double angleInRadians) {
return ((angleInRadians) * 180.0 / M_PI);
}
inline GPS_Coord GetLatLon(float x, RoadIdentifier &road) {
// select road parameters
double start_lat, start_lon, start_bearing, dx;
switch(road){
case RoadIdentifier::AB:
start_lat = I1_LAT;
start_lon = I1_LON;
start_bearing = ABC_B;
dx = (x - 50)*177.84/100.0;
break;
case RoadIdentifier::BC:
start_lat = I1_LAT;
start_lon = I1_LON;
start_bearing = ABC_B;
dx = (x + 50)*177.84/100.0;
break;
case RoadIdentifier::DE:
start_lat = I2_LAT;
start_lon = I2_LON;
start_bearing = DEF_B;
dx = (x - 50)*172.56/100.0;
break;
case RoadIdentifier::EF:
start_lat = I2_LAT;
start_lon = I2_LON;
start_bearing = DEF_B;
dx = (x + 50)*172.56/100.0;
break;
case RoadIdentifier::GH:
start_lat = I3_LAT;
start_lon = I3_LON;
start_bearing = GHI_B;
dx = (x - 50)*169.42/100.0;
break;
case RoadIdentifier::HI:
start_lat = I3_LAT;
start_lon = I3_LON;
start_bearing = GHI_B;
dx = (x + 50)*169.42/100.0;
break;
case RoadIdentifier::IH:
start_lat = I4_LAT;
start_lon = I4_LON;
start_bearing = IHG_B;
dx = (x - 50)*169.42/100.0;
break;
case RoadIdentifier::HG:
start_lat = I4_LAT;
start_lon = I4_LON;
start_bearing = IHG_B;
dx = (x + 50)*169.42/100.0;
break;
case RoadIdentifier::JK:
start_lat = I4_LAT;
start_lon = I4_LON;
start_bearing = JKL_B;
dx = (x - 50)*171.64/100.0;
break;
case RoadIdentifier::KL:
start_lat = I4_LAT;
start_lon = I4_LON;
start_bearing = JKL_B;
dx = (x + 50)*171.64/100.0;
break;
}
// convert real coordinates to latitude, longitude
double end_lat = asin( sin(start_lat)*cos(dx/R) + cos(start_lat)*sin(dx/R)*cos(start_bearing) );
double end_lon = start_lon + atan2( sin(start_bearing)*sin(dx/R)*cos(start_lat), cos(dx/R)-sin(start_lat)*sin(end_lat) );
end_lat = inDegrees(end_lat);
end_lon = inDegrees(end_lon);
end_lon = fmod(end_lon + 540, 360) - 180;
GPS_Coord coord {
.lat = end_lat,
.lon = end_lon
};
return coord;
}
#endif