create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / models / gravity / WGSGravityModel.java
1 package net.sf.openrocket.models.gravity;
2
3 import net.sf.openrocket.util.MathUtil;
4 import net.sf.openrocket.util.WorldCoordinate;
5
6 /**
7  * A gravity model based on the WGS84 ellipsoid.
8  * 
9  * @author Richard Graham <richard@rdg.cc>
10  */
11 public class WGSGravityModel implements GravityModel {
12         
13         // Cache the previously computed value
14         private WorldCoordinate lastWorldCoordinate;
15         private double lastg;
16         
17         
18         @Override
19         public double getGravity(WorldCoordinate wc) {
20                 
21                 // This is a proxy method to calcGravity, to avoid repeated calculation
22                 if (wc != this.lastWorldCoordinate) {
23                         this.lastg = calcGravity(wc);
24                         this.lastWorldCoordinate = wc;
25                 }
26                 
27                 return this.lastg;
28                 
29         }
30         
31         
32         @Override
33         public int getModID() {
34                 // The model is immutable, so it can return a constant mod ID
35                 return 0;
36         }
37         
38         
39         private double calcGravity(WorldCoordinate wc) {
40                 
41                 double sin2lat = MathUtil.pow2(Math.sin(wc.getLatitudeRad()));
42                 double g_0 = 9.7803267714 * ((1.0 + 0.00193185138639 * sin2lat) / Math.sqrt(1.0 - 0.00669437999013 * sin2lat));
43                 
44                 // Apply correction due to altitude. Note this assumes a spherical earth, but it is a small correction
45                 // so it probably doesn't really matter. Also does not take into account gravity of the atmosphere, again
46                 // correction could be done but not really necessary.
47                 double g_alt = g_0 * MathUtil.pow2(WorldCoordinate.REARTH / (WorldCoordinate.REARTH + wc.getAltitude()));
48                 
49                 return g_alt;
50         }
51         
52 }