-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatapoint.js
More file actions
191 lines (146 loc) · 3.48 KB
/
datapoint.js
File metadata and controls
191 lines (146 loc) · 3.48 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
class DataPoint {
static A_GRAVITY = 9.81; // Earth's gravitational acceleration
constructor() {
this.ts = 0;
this.hasGeodetic = false;
this.isValid = false;
this.lat = 0.0;
this.lon = 0.0;
this.hMSL = 0.0;
this.velN = 0.0;
this.velE = 0.0;
this.velD = 0.0;
this.hAcc = 0.0;
this.vAcc = 0.0;
this.sAcc = 0.0;
this.heading = 0.0;
this.cAcc = 0.0;
this.gpsFix = 0;
this.numSV = 0;
this.t = 0.0;
this.x = 0.0;
this.y = 0.0;
this.z = 0.0;
this.dist2D = 0.0;
this.dist3D = 0.0;
this.curv = 0.0;
this.accel = 0.0;
this.ax = 0.0;
this.ay = 0.0;
this.az = 0.0;
this.amag = 0.0;
this.lift = 0.0;
this.drag = 0.0;
this.vx = 0.0;
this.vy = 0.0;
this.theta = 0.0;
this.omega = 0.0;
}
static interpolate(p1, p2, a) {
const result = new DataPoint();
result.vx = p1.vx + a * (p2.vx - p1.vx);
result.vy = p1.vy + a * (p2.vy - p1.vy);
// Continue interpolating other fields as needed
return result;
}
static elevation(dp) {
return dp.z;
}
static northSpeed(dp) {
return dp.vy;
}
static eastSpeed(dp) {
return dp.vx;
}
static northSpeedRaw(dp) {
return dp.velN;
}
static eastSpeedRaw(dp) {
return dp.velE;
}
static verticalSpeed(dp) {
return dp.velD;
}
static horizontalSpeed(dp) {
return Math.sqrt(dp.velE * dp.velE + dp.velN * dp.velN);
}
static totalSpeed(dp) {
return Math.sqrt(dp.velE * dp.velE + dp.velN * dp.velN + dp.velD * dp.velD);
}
static diveAngle(dp) {
const pi = 3.14159265359;
return Math.atan2(dp.velD, Math.sqrt(dp.vx * dp.vx + dp.vy * dp.vy)) / pi * 180;
}
static curvature(dp) {
return dp.curv;
}
static glideRatio(dp) {
try {
if (dp.velD !== 0) {
return Math.sqrt(dp.velE * dp.velE + dp.velN * dp.velN) / dp.velD;
} else {
return 0;
}
} catch (e) {
return 0;
}
}
static horizontalAccuracy(dp) {
return dp.hAcc;
}
static verticalAccuracy(dp) {
return dp.vAcc;
}
static speedAccuracy(dp) {
return dp.sAcc;
}
static numberOfSatellites(dp) {
return dp.numSV;
}
static time(dp) {
return dp.t;
}
static distance2D(dp) {
return dp.dist2D;
}
static distance3D(dp) {
return dp.dist3D;
}
static acceleration(dp) {
return dp.accel;
}
static accForward(dp) {
return dp.ax;
}
static accRight(dp) {
return dp.ay;
}
static accDown(dp) {
return dp.az;
}
static accMagnitude(dp) {
return dp.amag;
}
static totalEnergy(dp) {
const v = DataPoint.totalSpeed(dp);
return v * v / 2 + DataPoint.A_GRAVITY * DataPoint.elevation(dp);
}
static energyRate(dp) {
return DataPoint.totalSpeed(dp) * DataPoint.acceleration(dp) - DataPoint.A_GRAVITY * DataPoint.verticalSpeed(dp);
}
static liftCoefficient(dp) {
return dp.lift;
}
static dragCoefficient(dp) {
return dp.drag;
}
static course(dp) {
return dp.theta;
}
static courseRate(dp) {
return dp.omega;
}
static courseAccuracy(dp) {
return dp.cAcc;
}
}