X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=ao-tools%2Fao-fakeflight%2Fao-physics.c;fp=ao-tools%2Fao-fakeflight%2Fao-physics.c;h=114b9e0f927da6304cdc6d2cd8f414287f0702d1;hb=248aaf5e76292c8e6bfa3600d2cf9b194bf66c86;hp=0000000000000000000000000000000000000000;hpb=4f2cbe0c537c9f417aae310cc3b89f84e0915103;p=fw%2Faltos diff --git a/ao-tools/ao-fakeflight/ao-physics.c b/ao-tools/ao-fakeflight/ao-physics.c new file mode 100644 index 00000000..114b9e0f --- /dev/null +++ b/ao-tools/ao-fakeflight/ao-physics.c @@ -0,0 +1,53 @@ +/* + * Copyright © 2014 Keith Packard + * + * 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; version 2 of the License. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao-fakeflight.h" + +/* Density of dry air in kg/m³ for a given pressure and temperature. */ +double +density_air(double pressure, /* Pa */ + double temperature) /* °C */ +{ + return pressure / (GAS_CONSTANT * (temperature + 273.15)); +} + +/* Area of a circle */ +double +area_circle(double diameter) +{ + double radius = diameter / 2; + return M_PI * radius * radius; +} + +/* Force due to drag (N) */ +double +force_drag(double speed, /* m/s */ + double rho, /* kg/m³ */ + double cd, /* unitless */ + double area) /* m² */ +{ + return 0.5 * rho * (speed * speed) * cd * area; +} + +/* Force due to gravity (N) */ +double +force_gravity(double mass, /* kg */ + double altitude) /* m */ +{ + double distance = altitude + EARTH_RADIUS; + return GRAVITATIONAL_CONSTANT * EARTH_MASS * mass / (distance * distance); +}