a216528bec7b6fc90fd987dd57773963c800e3c5
[debian/openrocket] / src / net / sf / openrocket / models / gravity / BasicGravityModel.java
1 package net.sf.openrocket.models.gravity;
2
3 /**
4  * A gravity model based on the International Gravity Formula of 1967.  The gravity
5  * value is computed when the object is constructed and later returned as a static
6  * value.
7  * 
8  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
9  */
10 public class BasicGravityModel implements GravityModel {
11         
12         private final double g;
13         
14         /**
15          * Construct the static gravity model at the specific latitude (in degrees).
16          * @param latitude      the latitude in degrees (-90 ... 90)
17          */
18         public BasicGravityModel(double latitude) {
19                 // TODO: HIGH: This model is wrong!!  Increases monotonically from -90 to 90
20                 double sin = Math.sin(latitude * Math.PI / 180);
21                 double sin2 = Math.sin(2 * latitude * Math.PI / 180);
22                 g = 9.780327 * (1 + 0.0053024 * sin - 0.0000058 * sin2);
23         }
24         
25         @Override
26         public double getGravity(double altitude) {
27                 return g;
28         }
29         
30         @Override
31         public int getModID() {
32                 // Return constant mod ID
33                 return (int) (g * 1000000);
34         }
35         
36 }