1 package net.sf.openrocket.models.atmosphere;
4 * An abstract atmospheric model that pre-computes the conditions on a number of layers
5 * and later linearly interpolates the values from between these layers.
7 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
9 public abstract class InterpolatingAtmosphericModel implements AtmosphericModel {
10 /** Layer thickness of interpolated altitude. */
11 private static final double DELTA = 500;
13 private AtmosphericConditions[] levels = null;
16 public AtmosphericConditions getConditions(double altitude) {
22 if (altitude >= DELTA * (levels.length - 1))
23 return levels[levels.length - 1];
25 int n = (int) (altitude / DELTA);
26 double d = (altitude - n * DELTA) / DELTA;
27 AtmosphericConditions c = new AtmosphericConditions();
28 c.setTemperature(levels[n].getTemperature() * (1 - d) + levels[n + 1].getTemperature() * d);
29 c.setPressure(levels[n].getPressure() * (1 - d) + levels[n + 1].getPressure() * d);
35 private void computeLayers() {
36 double max = getMaxAltitude();
37 int n = (int) (max / DELTA) + 1;
38 levels = new AtmosphericConditions[n];
39 for (int i = 0; i < n; i++) {
40 levels[i] = getExactConditions(i * DELTA);
45 protected abstract double getMaxAltitude();
47 protected abstract AtmosphericConditions getExactConditions(double altitude);