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 /* Mass (kg) of the airframe */
22 rocket_mass(struct flight *f, struct rocket *r)
24 double time = f->time;
25 double m = r->empty_mass;
28 for (n = 0; n < MAX_MOTORS; n++) {
29 struct motor *motor = &r->motors[n];
30 if (motor->burn_time) {
31 double fuel_time_remain = fmin (motor->burn_time, fmax(motor->burn_time - (time - motor->delay), 0.0));
32 double fuel_fraction = fuel_time_remain / motor->burn_time;
33 m += fuel_fraction * motor->fuel_mass;
39 /* Force (N) due to thrust */
41 rocket_thrust(struct flight *f, struct rocket *r)
43 double time = f->time;
47 for (n = 0; n < MAX_MOTORS; n++) {
48 struct motor *motor = &r->motors[n];
49 if (motor->burn_time) {
50 if (motor->delay <= time && time < motor->delay + motor->burn_time)
51 thrust += motor->average_thrust;
57 /* Drag (N) due to air resistance */
59 rocket_drag(struct flight *f, struct rocket *r)
61 double pressure = cc_altitude_to_pressure(f->altitude);
62 double temperature = cc_altitude_to_temperature(f->altitude);
63 double drag = force_drag(f->speed, density_air(pressure, temperature),
64 r->models[f->state].cd,
65 area_circle(r->models[f->state].diameter));
67 /* drag operates in opposition to motion through air */
74 /* Force (N) due to gravity */
76 rocket_gravity(struct flight *f, struct rocket *r)
78 double gravity = force_gravity(rocket_mass (f, r), f->altitude);