2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 #include "ao-fakeflight.h"
20 /* Density of dry air in kg/m³ for a given pressure and temperature. */
22 density_air(double pressure, /* Pa */
23 double temperature) /* °C */
25 return pressure / (GAS_CONSTANT * (temperature + 273.15));
28 /* Area of a circle */
30 area_circle(double diameter)
32 double radius = diameter / 2;
33 return M_PI * radius * radius;
36 /* Force due to drag (N) */
38 force_drag(double speed, /* m/s */
39 double rho, /* kg/m³ */
40 double cd, /* unitless */
43 return 0.5 * rho * (speed * speed) * cd * area;
46 /* Force due to gravity (N) */
48 force_gravity(double mass, /* kg */
49 double altitude) /* m */
51 double distance = altitude + EARTH_RADIUS;
52 return GRAVITATIONAL_CONSTANT * EARTH_MASS * mass / (distance * distance);