version 1.1.9
[debian/openrocket] / src / net / sf / openrocket / models / gravity / WGSGravityModel.java
index 9339c0eb7e5cd2380a0d56a333c57c7da4e45dd5..41fb5c233863cd2fc43a19c35ea1211c0bba2d4e 100644 (file)
@@ -4,19 +4,16 @@ import net.sf.openrocket.util.MathUtil;
 import net.sf.openrocket.util.WorldCoordinate;
 
 /**
- * A gravity model based on the WGS84 elipsoid.
+ * A gravity model based on the WGS84 ellipsoid.
  * 
  * @author Richard Graham <richard@rdg.cc>
  */
 public class WGSGravityModel implements GravityModel {
        
+       // Cache the previously computed value
        private WorldCoordinate lastWorldCoordinate;
        private double lastg;
        
-
-       private static int hit = 0;
-       private static int miss = 0;
-       
        
        @Override
        public double getGravity(WorldCoordinate wc) {
@@ -25,12 +22,7 @@ public class WGSGravityModel implements GravityModel {
                if (wc != this.lastWorldCoordinate) {
                        this.lastg = calcGravity(wc);
                        this.lastWorldCoordinate = wc;
-                       
-                       miss++;
-               } else {
-                       hit++;
                }
-               System.out.println("GRAVITY MODEL:  hit=" + hit + " miss=" + miss);
                
                return this.lastg;
                
@@ -52,7 +44,7 @@ public class WGSGravityModel implements GravityModel {
                // Apply correction due to altitude. Note this assumes a spherical earth, but it is a small correction
                // so it probably doesn't really matter. Also does not take into account gravity of the atmosphere, again
                // correction could be done but not really necessary.
-               double g_alt = g_0 * Math.pow(WorldCoordinate.REARTH / (WorldCoordinate.REARTH + wc.getAltitude()), 2);
+               double g_alt = g_0 * MathUtil.pow2(WorldCoordinate.REARTH / (WorldCoordinate.REARTH + wc.getAltitude()));
                
                return g_alt;
        }