geodetic computations
[debian/openrocket] / 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 elipsoid.
8  * 
9  * @author Richard Graham <richard@rdg.cc>
10  */
11
12 public class WGSGravityModel implements GravityModel {
13         
14         private WorldCoordinate lastWorldCoordinate;
15         private double lastg;
16         
17         @Override
18         public double getGravity(WorldCoordinate wc) {
19                 
20                 // This is a proxy method to calcGravity, to avoid repeated calculation
21                 if (wc != this.lastWorldCoordinate) {
22                         this.lastg = calcGravity(wc);
23                         this.lastWorldCoordinate = wc;
24                 }
25                 
26                 return this.lastg;
27                 
28         }
29         
30         private double calcGravity(WorldCoordinate wc) {
31                 
32                 double sin2lat = MathUtil.pow2(Math.sin(wc.getLatitudeRad()));
33                 double g_0 = 9.7803267714 * ((1.0 + 0.00193185138639 * sin2lat) / Math.sqrt(1.0 - 0.00669437999013 * sin2lat));
34                 
35                 // Apply correction due to altitude. Note this assumes a spherical earth, but it is a small correction
36                 // so it probably doesn't really matter. Also does not take into account gravity of the atmosphere, again
37                 // correction could be done but not really necessary.
38                 double g_alt = g_0 * Math.pow(WorldCoordinate.REARTH / (WorldCoordinate.REARTH + wc.getAltitude()), 2);
39                 
40                 return g_alt;
41         }
42         
43 }