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 private WorldCoordinate lastWorldCoordinate;
17 private static int hit = 0;
18 private static int miss = 0;
22 public double getGravity(WorldCoordinate wc) {
24 // This is a proxy method to calcGravity, to avoid repeated calculation
25 if (wc != this.lastWorldCoordinate) {
26 this.lastg = calcGravity(wc);
27 this.lastWorldCoordinate = wc;
33 System.out.println("GRAVITY MODEL: hit=" + hit + " miss=" + miss);
41 public int getModID() {
42 // The model is immutable, so it can return a constant mod ID
47 private double calcGravity(WorldCoordinate wc) {
49 double sin2lat = MathUtil.pow2(Math.sin(wc.getLatitudeRad()));
50 double g_0 = 9.7803267714 * ((1.0 + 0.00193185138639 * sin2lat) / Math.sqrt(1.0 - 0.00669437999013 * sin2lat));
52 // Apply correction due to altitude. Note this assumes a spherical earth, but it is a small correction
53 // so it probably doesn't really matter. Also does not take into account gravity of the atmosphere, again
54 // correction could be done but not really necessary.
55 double g_alt = g_0 * Math.pow(WorldCoordinate.REARTH / (WorldCoordinate.REARTH + wc.getAltitude()), 2);