1 package net.sf.openrocket.aerodynamics;
3 public abstract class AtmosphericModel {
4 /** Layer thickness of interpolated altitude. */
5 private static final double DELTA = 500;
7 private AtmosphericConditions[] levels = null;
10 public AtmosphericConditions getConditions(double altitude) {
16 if (altitude >= DELTA*(levels.length-1))
17 return levels[levels.length-1];
19 int n = (int)(altitude/DELTA);
20 double d = (altitude - n*DELTA)/DELTA;
21 AtmosphericConditions c = new AtmosphericConditions();
22 c.temperature = levels[n].temperature * (1-d) + levels[n+1].temperature * d;
23 c.pressure = levels[n].pressure * (1-d) + levels[n+1].pressure * d;
29 private void computeLayers() {
30 double max = getMaxAltitude();
31 int n = (int)(max/DELTA) + 1;
32 levels = new AtmosphericConditions[n];
33 for (int i=0; i < n; i++) {
34 levels[i] = getExactConditions(i*DELTA);
39 public abstract double getMaxAltitude();
40 public abstract AtmosphericConditions getExactConditions(double altitude);