-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_aero.h
369 lines (327 loc) · 12.4 KB
/
math_aero.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/**
* math_aero
* Copyright (C) 2021 Norbert Kiszka <norbert at linux dot pl>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MATH_AERO_H
#define MATH_AERO_H
extern const double c_knots_to_metersPerSecond;
extern const double c_metersPerSecond_to_knots;
extern const double c_rgas_stp_iso;
extern const double c_rgas_water;
inline double mps_to_knt(double mps)
{
return mps * c_metersPerSecond_to_knots;
}
inline double knt_to_mps(double knt)
{
return knt * c_knots_to_metersPerSecond;
}
typedef struct mass_point_s
{
double distance; // distance in meters from nose tip (center of mass of one single object)
double mass; // in kg
} mass_point_t;
/**
* Calculate dew point with David Bolton method.
* @param temp Temperature in K
* @param humidity Humidity in number (0.5 = 50%)
* @return Dew point in K
*/
double calc_dew_point(double temp, double humidity);
/**
* Calculate air water saturation (Arden Buck equation).
* @param temp Temperature in K
* @return Saturation pressure in Pa
*/
double calc_air_saturation(double temp);
/**
* Calculate air water saturation (Tetens/Murray equation).
* @note Arden Buck equation is more precise (up to ~3%).
* @param temp Temperature in K
* @return Saturation pressure in Pa
*/
double calc_air_saturation_tetens(double temp);
/**
* Calculate air gas constant in humid air
* @param pressure Pressure in Pa
* @param temp Temperature in K
* @param humidity Humidity in number (0.5 = 50%)
* @return m2/s2/K
*/
double calc_air_gas_constant(double pressure, double temp, double humidity);
/**
* Calculate air density (Rho).
* Humidity has bigger affect on density in higher temperatures - in those conditions air is less dense, so its important in calculations.
* @param pressure Pressure in Pa
* @param temp Temperature in K
* @param humidity Humidity in number (0.5 = 50%)
* @return Air density in kg/m^3
*/
double calc_air_density(double pressure, double temp, double humidity);
/**
* Calculate air density (Rho). Method by Herman Wobus.
* @param pressure Pressure in Pa
* @param temp Temperature in K
* @param humidity Humidity in number (0.5 = 50%)
* @return Air density in kg/m^3
*/
double calc_air_density_herman_wobus(double pressure, double temp, double humidity);
/**
* Calculate air dynamic pressure
* @param air_density Air density in kg/m^3
* @param air_pressure Air pressure in Pa
* @param velocity Object velocity relative to air (m/s)
* @return Dynamic pressure in Pa
*/
double calc_dynamic_pressure(double air_density, double air_pressure, double velocity);
/**
* Calculate fluid (air) drag.
* @param density Fluid density in kg/m^3
* @param velocity Velocity in m/s
* @param drag_coefficient Drag coefficient
* @param area Area in m^2
* @return Drag in N
*/
double calc_drag(double density, double velocity, double drag_coefficient, double area);
/**
* Calculate drag coefficient.
* @param density Fluid density in kg/m^3
* @param velocity Velocity in m/s
* @param drag_coefficient Drag coefficient
* @param area Area in m^2
* @return Cd
*/
double calc_cd(double density, double velocity, double drag_force, double area);
/**
* Calculate fluid (air) lift.
* @param density Fluid density in kg/m^3
* @param velocity Velocity in m/s
* @param lift_coefficient Lift coefficient
* @param area Area in m^2
* @return Lift in N
*/
double calc_lift(double density, double velocity, double lift_coefficient, double area);
/**
* Calculate lift coefficient.
* @param density Fluid density in kg/m^3
* @param velocity Velocity in m/s
* @param lift_coefficient Lift coefficient
* @param area Area in m^2
* @return Cd
*/
double calc_cl(double density, double velocity, double lift_force, double area);
/**
* Calculate speed for given force, lift coefficient etc.
* @param density Fluid density in kg/m^3
* @param lift_coefficient Lift coefficient
* @param force lift force (mass * 1g = mass * 9.80665)
* @param area Area in m^2
* @return Speed in m/s
*/
double calc_speed_for_force(double density, double lift_coefficient, double force, double area);
/**
* Calculate speed of sound in air via air density and air pressure
* @param air_density Air density in kg/m^3
* @param air_pressure Air pressure in Pa
* @return Speed of sound in m/s
*/
double calc_speed_of_sound(double air_density, double air_pressure);
/**
* Does anybody need this very comlicated mathematic function?
* @param velocity Velocity in m/s
* @param speed_of_sound Speed of sound in m/s
* @return Mach number (Mach speed)
*/
double calc_mach_number(double velocity, double speed_of_sound);
/**
* Calculate moment (torque) generated by airfoil
* @param moment_coefficient Airfoil moment coefficient
* @param area Airfoil area in m^2
* @param chord Chord length in m
* @param velocity Velocity in m/s
* @param density Fluid density in kg/m^3
* @param pressure Fluid pressure in Pa
* @return Torque in Nm
*/
double calc_pitching_moment_airfoil(double moment_coefficient, double area, double chord, double velocity, double density, double pressure);
/**
* Calculate pitching moment (torque) of whole aircraft in relative to cg
* @param cg center of gravity
* @param lift_wings Lift force (25% chord) generated by both wings
* @param pm_wings Moment (torque at 25% chord) generated by wings
* @param cp_wings Center of pressure in wings (25% chord in most cases)
* @param lift_fuselage Lift force (25% chord) generated by fuselage
* @param pm_fuselage Moment (torque at 25% chord) generated by fuselage
* @param cp_fuselage Center of pressure in fuselage (25% chord in most cases)
* @param lift_hs Lift force (25% chord) generated by horizontal stabilizer(s)
* @param pm_hs Moment (torque at 25% chord) generated by horizontal stabilizer
* @param cp_wings Center of pressure in horizontal stabilizer(s) (25% chord in most cases)
* @return Torque in Nm
*/
double calc_pitching_moment_aircraft(double cg, double lift_wings, double pm_wings, double cp_wings, double lift_fuselage, double pm_fuselage, double cp_fuselage, double lift_hs, double pm_hs, double cp_hs);
/**
* Air dynamic viscosity from Sutherlands Equation.
* @param temp Temperature in K
* @return Dynamic viscosity in Pa/s
*/
double calc_dynamic_viscosity(double temp);
/**
* Calculate Reynolds number
* @param velocity Velocity in m/s
* @param chord Chord length in m
* @param density Fluid density
* @param temp Fluid temperature in K
* @return Reynolds number
*/
double calc_reynold(double velocity, double chord, double density, double temp);
/**
* Calculate Reynolds number (unsigned long)
* @param velocity Velocity in m/s
* @param chord Chord length in m
* @param density Fluid density
* @param temp Fluid temperature in K
* @return Reynolds number
*/
unsigned long calc_reynold_ul(double velocity, double chord, double density, double temp);
/**
* Calculate air pressure at given altitude
* @note This function is very accurate, but up to altitude 11 000 m (36 089 ft). Above this altitude (36 089 ft), this cannot be safely used in any aircraft, because temperature lapse rate is much different than in troposphere. In other words: above troposhpere, this function will give error, that will be increasing with every feet.
* @param qnh QNH in Pa
* @param altitude Altitude in m
* @param gravity_acceleration Local gravity acceleration in m/s^2 (use 9.80665 for FL or if unsure)
* @param temp_deviation Temperature deviation from ISA (Example: sea level is 20 °C, then use 5. Example2: sea level is 11 °C, then use -4)
* @return Pressure in Pa
*/
double calc_air_pressure(double qnh, double altitude, double gravity_acceleration, double temp_deviation);
/**
* Calculate air pressure at given altitude - method probably by Mark Drela.
* @note This funtion was not fully tested. Please dont use this function in any aircraft.
* @param qnh QNH in Pa
* @param altitude Altitude in m
* @return Pressure in Pa
*/
double calc_air_pressure_mark_drela(double qnh, double altitude);
/**
* Calculate barometric altitude (aka pressure altitude)
* @note This function is very accurate, but up to altitude 11 000 m (36 089 ft). Above this altitude (36 089 ft), this cannot be safely used in any aircraft, because (above 36 089 ft) temperature lapse rate is much different than in troposphere. In other words: above troposhpere, this function will give error, that will be increased with every feet.
* @param qnh QNH in Pa (use 101325 for determine FL)
* @param pressure Pressure in Pa
* @return altitude in m
*/
double calc_barometric_altitude(double qnh, double pressure);
/**
* Calculate density altitude (true altitude)
* @param qnh QNH in Pa
* @param pressure Pressure in Pa
* @param temp outside air temperature
* @param gravity_acceleration local gravity_acceleration
* @param humidity
* @return altitude in m
*/
double calc_density_altitude(double qnh, double pressure, double temp, double gravity_acceleration, double humidity);
/**
* Calculate temperature rise by air compressibility
* @param sat outside air temperature
* @param mach_speed object Mach speed
* @return temperature delta in K
*/
double calc_temperature_ram_rise(double sat, double mach_speed);
/**
* Calculate outside temperature from ram rise
* @param rr Temperature ram rise (difference between TAT and SAT)
* @param mach_speed object Mach speed
* @return SAT temperature in K
*/
double calc_sat_from_ram_rise(double rr, double mach_speed);
/**
* Calculate SAT from TAT with given Mach speed
* @param tat TAT temperature
* @param mach_speed Mach number
* @return SAT (outside air temperature)
*/
double calc_sat_from_tat(double tat, double mach_speed);
/**
* Method borrowed (rewrited from JavaScript and modified) from Joachim K. Hochwarth method.
* Source http://www.hochwarth.com/misc/AviationCalculator.html
* Version: 1.8.2 (Joachim K. Hochwarth).
* @param cas CAS speed
* @param pressure Air static pressure
* @return Mach number (Mach speed)
*/
double calc_Mach_from_CAS(double cas, double pressure);
/**
* Calculate TAS from Mach
* @param mach Mach speed
* @param a Local speed of sound (around whole aircraft)
* @return TAS speed
*/
double calc_TAS_from_Mach(double mach, double a);
/**
* Calculate EAS from TAS
* @param tas TAS speed
* @param density Local air density
* @return EAS speed
*/
double calc_EAS_from_TAS(double tas, double density);
/**
* Calculate TAS from EAS
* @param eas EAS speed
* @param density Local air density
* @return TAS speed
*/
double calc_TAS_from_EAS(double eas, double density);
/**
* Method borrowed (rewrited and modified from JavaScript) from Joachim K. Hochwarth method.
* Source http://www.hochwarth.com/misc/AviationCalculator.html
* Version: 1.8.2 (Joachim K. Hochwarth).
* @param cas CAS speed
* @param pressure Air static pressure
* @param a Local speed of sound (around whole aircraft)
* @return CAS speed
*/
double calc_CAS_from_TAS(double tas, double pressure, double a);
/**
* Calculate center of gravity
* @note distance (struct mass_point_t) cant be zero or less than zero (distance = distance from aircraft nose tip).
* @param points Points array
* @param n Number of points
* @return CG position
*/
double calc_cg(mass_point_t *points, size_t n);
/**
* Calculate sum of mass in points array
* @param points Points array
* @param n Number of points
* @return Total mass
*/
double calc_total_mass(mass_point_t *points, size_t n);
/**
* Calculate moment of inertia from mass points relative to CG (2D object - two axis)
* @param cg Center of Gravity
* @param points Points array
* @param n Number of points
* @return Moment of inertia in kg/m^2
*/
double calc_moment_of_inertia(double cg, mass_point_t *points, size_t n);
/**
* Calculate (theoretical) angular acceleration with given points array
* @param torque Torque in Nm
* @param points Points array
* @param n Number of points
* @return Angular acceleration in rad/s^2
*/
double calc_angular_acceleration(double torque, mass_point_t *points, size_t n);
#endif