1 package net.sf.openrocket.models.gravity;
3 import net.sf.openrocket.util.MathUtil;
4 import net.sf.openrocket.util.WorldCoordinate;
7 * A gravity model based on the WGS84 elipsoid.
9 * @author Richard Graham <richard@rdg.cc>
11 public class WGSGravityModel implements GravityModel {
13 // Cache the previously computed value
14 private WorldCoordinate lastWorldCoordinate;
19 public double getGravity(WorldCoordinate wc) {
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;
33 public int getModID() {
34 // The model is immutable, so it can return a constant mod ID
39 private double calcGravity(WorldCoordinate wc) {
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));
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 * Math.pow(WorldCoordinate.REARTH / (WorldCoordinate.REARTH + wc.getAltitude()), 2);