Grid interpolator of earths gravity based on data from the International Center for Global Earth Models (ICGEM). Reference: http://icgem.gfz-potsdam.de/ICGEM/ICGEM.html. More...
Public Member Functions | |
| GravityEarthGfcGrid () | |
| Constructs an uninitialized gravity earth object. | |
| GravityEarthGfcGrid (string gridFilename) | |
| Constructs a gravity earth object and initializes it by loading a model. | |
| double | Calculate (double lat, double lon, double h) |
| Calculate the acceleration g from grid using bicubic interpolation. Requires a map file to be loaded. | |
| void | LoadGravityMap (string gridFilename) |
| Populate the gravity value map from an external file. Assumes the grid is in .gdf format from over the value range lat [-90,90] and long [0,360] in one degree steps. | |
| void | UnloadGravityMap () |
| Dispose of the current gravity map. | |
Properties | |
| int | Size [get] |
| Gets the number of gridpoints loaded. | |
Grid interpolator of earths gravity based on data from the International Center for Global Earth Models (ICGEM). Reference: http://icgem.gfz-potsdam.de/ICGEM/ICGEM.html.
Definition at line 19 of file GravityEarthGfcGrid.cs.
| NewGamePhysics.Physics.GravityEarthGfcGrid.GravityEarthGfcGrid | ( | ) |
Constructs an uninitialized gravity earth object.
Definition at line 55 of file GravityEarthGfcGrid.cs.
| NewGamePhysics.Physics.GravityEarthGfcGrid.GravityEarthGfcGrid | ( | string | gridFilename | ) |
Constructs a gravity earth object and initializes it by loading a model.
| modelFilename | The gdf grid file to load. |
Definition at line 64 of file GravityEarthGfcGrid.cs.
00065 { 00066 this.LoadGravityMap(gridFilename); 00067 }
| double NewGamePhysics.Physics.GravityEarthGfcGrid.Calculate | ( | double | lat, | |
| double | lon, | |||
| double | h | |||
| ) |
Calculate the acceleration g from grid using bicubic interpolation. Requires a map file to be loaded.
| lat | Latitude (deg) in the range [-90,90] | |
| lon | Longitude (deg) in the range [0,360] | |
| h | Height (m) above sealevel in the range [0,100000]. |
Definition at line 86 of file GravityEarthGfcGrid.cs.
00087 { 00088 if (null == this.grid) 00089 { 00090 throw new ApplicationException( 00091 "Gravity map not initialized. Load one first."); 00092 } 00093 00094 if ((lat < -90.0) || (lat > 90.0)) 00095 { 00096 throw new ArgumentOutOfRangeException("lat"); 00097 } 00098 00099 if ((lon < 0.0) || (lon > 360.0)) 00100 { 00101 throw new ArgumentOutOfRangeException("lon"); 00102 } 00103 00104 if ((h < 0.0) || (h > 100000.0)) 00105 { 00106 throw new ArgumentOutOfRangeException("h"); 00107 } 00108 00109 // Calculate index position 00110 int intLat = (int)Math.Truncate(lat); 00111 int intLon = (int)Math.Truncate(lon); 00112 00113 // Create bicubic interpolator matrix 00114 double[,] G = new double[4, 4]; 00115 for (int i = -1; i <= 2; i++) 00116 { 00117 for (int j = -1; j <= 2; j++) 00118 { 00119 int indexLat = LatWrap(intLat + i) - LatMin; 00120 int indexLon = LonWrap(intLon + j) - LonMin; 00121 G[i+1,j+1] = grid[indexLat, indexLon]; 00122 } 00123 } 00124 00125 // Interpolate over grid 00126 Bicubic bicubic = new Bicubic(G); 00127 double x = Math.Abs(lat - (double)intLat); 00128 double y = lon - (double)intLon; 00129 double g = bicubic.Calc(x,y); 00130 00131 // Scale from mgal units 00132 g *= 1e-5; 00133 00134 // Adjust for elevation 00135 g -= (3.086e-6 * h); 00136 00137 return g; 00138 }
| void NewGamePhysics.Physics.GravityEarthGfcGrid.LoadGravityMap | ( | string | gridFilename | ) |
Populate the gravity value map from an external file. Assumes the grid is in .gdf format from over the value range lat [-90,90] and long [0,360] in one degree steps.
| gridFilename | The grid file to load. |
Definition at line 146 of file GravityEarthGfcGrid.cs.
00147 { 00148 // Create new grid 00149 size = 0; 00150 grid = new double[(LatMax - LatMin + 1), (LonMax - LonMin + 1)]; 00151 00152 // Prep data reader 00153 Scanf scanf = new Scanf(); 00154 FileStream fileStream = null; 00155 StreamReader streamReader = null; 00156 try 00157 { 00158 fileStream = new FileStream(gridFilename, FileMode.Open); 00159 streamReader = new StreamReader(fileStream); 00160 string line; 00161 while ((line = streamReader.ReadLine()) != null) 00162 { 00163 object[] o = scanf.Scan(line, " %lf %lf %lf"); 00164 if ((null != o) && (o.Length == 3)) 00165 { 00166 int lon = (int)Math.Truncate((double)o[0]); 00167 int lat = (int)Math.Truncate((double)o[1]); 00168 double g = (double)o[2]; 00169 00170 // Check if the grid indices are in the right range 00171 if ((lat < LatMin) || (lat > LatMax) || (lon < LonMin) || (lon > LonMax)) 00172 { 00173 throw new Exception("Invalid data: " + line); 00174 } 00175 00176 int latIndex = lat - LatMin; 00177 int lonIndex = lon - LonMin; 00178 00179 // Make sure we don't double write a grid point 00180 if (grid[latIndex, lonIndex] != 0.0) 00181 { 00182 throw new Exception("Double grid value: " + line); 00183 } 00184 00185 // Store value in grid 00186 grid[latIndex, lonIndex] = g; 00187 size++; 00188 } 00189 } 00190 } 00191 finally 00192 { 00193 if (null != streamReader) 00194 { 00195 streamReader.Close(); 00196 } 00197 if (null != fileStream) 00198 { 00199 fileStream.Close(); 00200 } 00201 } 00202 }
| void NewGamePhysics.Physics.GravityEarthGfcGrid.UnloadGravityMap | ( | ) |
Dispose of the current gravity map.
Definition at line 207 of file GravityEarthGfcGrid.cs.
int NewGamePhysics.Physics.GravityEarthGfcGrid.Size [get] |
Gets the number of gridpoints loaded.
Definition at line 73 of file GravityEarthGfcGrid.cs.
1.6.2