1 /**
2  * \file NETGeographicLib\GravityPanel.cs
3  * \brief NETGeographicLib.GravityModel example
4  *
5  * NETGeographicLib.GravityModel,
6  * NETGeographicLib.NormalGravity, and
7  * NETGeographicLib.GravityCircle example.
8  *
9  * NETGeographicLib is copyright (c) Scott Heiman (2013)
10  * GeographicLib is Copyright (c) Charles Karney (2010-2012)
11  * <charles@karney.com> and licensed under the MIT/X11 License.
12  * For more information, see
13  * https://geographiclib.sourceforge.io/
14  **********************************************************************/
15 using System;
16 using System.Collections.Generic;
17 using System.ComponentModel;
18 using System.Drawing;
19 using System.Data;
20 using System.Linq;
21 using System.Text;
22 using System.Windows.Forms;
23 using NETGeographicLib;
24 
25 namespace Projections
26 {
27     public partial class GravityPanel : UserControl
28     {
29         GravityModel m_gm = null;
30         string m_path;
31         string m_name;
GravityPanel()32         public GravityPanel()
33         {
34             InitializeComponent();
35         }
36 
OnSelectGravityModel(object sender, EventArgs e)37         private void OnSelectGravityModel(object sender, EventArgs e)
38         {
39             OpenFileDialog dlg = new OpenFileDialog();
40             dlg.Filter = "Gravity Model (*.egm)|*.egm";
41             dlg.DefaultExt = "egm";
42 
43             if (dlg.ShowDialog() == DialogResult.Cancel) return;
44 
45             m_path = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf('\\')).Replace('\\', '/');
46             int length = dlg.FileName.LastIndexOf('.') - dlg.FileName.LastIndexOf('\\') - 1;
47             m_name = dlg.FileName.Substring(dlg.FileName.LastIndexOf('\\') + 1, length);
48 
49             try
50             {
51                 m_gm = new GravityModel(m_name, m_path);
52                 m_gravityModelNameTextBox.Text = dlg.FileName;
53                 m_nameTextBox.Text = m_gm.GravityModelName;
54                 m_descriptionTextBox.Text = m_gm.Description;
55                 m_dateTextBox.Text = m_gm.DateTime;
56                 m_updateButton.Enabled = true;
57                 m_normGravButton.Enabled = true;
58                 m_GravityCircleButton.Enabled = true;
59                 m_validateButton.Enabled = true;
60             }
61             catch (Exception xcpt)
62             {
63                 MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
64             }
65         }
66 
OnUpdate(object sender, EventArgs e)67         private void OnUpdate(object sender, EventArgs e)
68         {
69             Cursor = Cursors.WaitCursor;
70             try
71             {
72                 double lon = Double.Parse(m_longitudetextBoxT.Text);
73                 double lat = Double.Parse(m_latitudeTextBox.Text);
74                 double alt = Double.Parse(m_altitudeTextBox.Text);
75 
76                 double gx, gy, gz;
77                 m_gm.Gravity(lat, lon, alt, out gx, out gy, out gz);
78                 m_accelXTextBox.Text = gx.ToString();
79                 m_accelYTextBox.Text = gy.ToString();
80                 m_accelZTextBox.Text = gz.ToString();
81                 m_geoidTextBox.Text = m_gm.GeoidHeight(lat, lon).ToString();
82                 Cursor = Cursors.Default;
83             }
84             catch (Exception xcpt)
85             {
86                 Cursor = Cursors.Default;
87                 MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
88             }
89         }
90 
OnNormGravity(object sender, EventArgs e)91         private void OnNormGravity(object sender, EventArgs e)
92         {
93             try
94             {
95                 double lat = Double.Parse(m_latitudeTextBox.Text);
96                 double alt = Double.Parse(m_altitudeTextBox.Text);
97 
98                 double gx, gz;
99                 NormalGravity ng = m_gm.ReferenceEllipsoid();
100                 ng.Gravity(lat, alt, out gx, out gz);
101                 m_accelXTextBox.Text = gx.ToString();
102                 m_accelYTextBox.Text = "0.0";
103                 m_accelZTextBox.Text = gz.ToString();
104             }
105             catch (Exception xcpt)
106             {
107                 MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
108             }
109 
110         }
111 
OnGravityCircle(object sender, EventArgs e)112         private void OnGravityCircle(object sender, EventArgs e)
113         {
114             Cursor = Cursors.WaitCursor;
115             try
116             {
117                 double lon = Double.Parse(m_longitudetextBoxT.Text);
118                 double lat = Double.Parse(m_latitudeTextBox.Text);
119                 double alt = Double.Parse(m_altitudeTextBox.Text);
120 
121                 double gx, gy, gz;
122                 GravityCircle gc = m_gm.Circle(lat, alt, GravityModel.Mask.GEOID_HEIGHT|GravityModel.Mask.GRAVITY);
123                 gc.Gravity(lon, out gx, out gy, out gz);
124                 m_accelXTextBox.Text = gx.ToString();
125                 m_accelYTextBox.Text = gy.ToString();
126                 m_accelZTextBox.Text = gz.ToString();
127                 if (alt != 0.0)
128                     MessageBox.Show("Geoid height cannot be calculated with GravityCircle if altitude is not 0", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
129                 else
130                     m_geoidTextBox.Text = gc.GeoidHeight(lon).ToString();
131                 Cursor = Cursors.Default;
132             }
133             catch (Exception xcpt)
134             {
135                 Cursor = Cursors.Default;
136                 MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
137             }
138         }
139 
OnValidate(object sender, EventArgs e)140         private void OnValidate(object sender, EventArgs e)
141         {
142             try
143             {
144                 double lon = -86.0;
145                 double lat = 32.0;
146                 double alt = 0.0;
147 
148                 double x, y, z;
149                 GravityModel gm = new GravityModel(m_name,m_path);
150                 gm.Disturbance( lat, lon, alt, out x, out y, out z);
151                 gm.GeoidHeight(lat,lon);
152                 gm.Gravity(lat,lon,alt,out x,out y, out z);
153                 gm.Phi(5000000.0,5000000.0,out x,out y);
154                 gm.SphericalAnomaly(lat,lon,alt,out x, out y, out z);
155                 gm.T(5000000.0,5000000.0,5000000.0);
156                 gm.U(5000000.0,5000000.0,5000000.0,out x,out y,out z);
157                 gm.V(5000000.0,5000000.0,5000000.0,out x,out y,out z);
158                 gm.W(5000000.0,5000000.0,5000000.0,out x,out y,out z);
159                 NormalGravity ng = new NormalGravity(NormalGravity.StandardModels.GRS80);
160                 ng = new NormalGravity( NormalGravity.StandardModels.WGS84);
161                 ng = new NormalGravity(6378137.0,3.986005e+14,7.292115147e-5,1.08263e-3, false);
162                 ng = gm.ReferenceEllipsoid();
163                 ng.DynamicalFormFactor(1);
164                 Geocentric geo = ng.Earth();
165                 ng.Gravity(lat,alt,out x, out z);
166                 ng.Phi(5000000.0,5000000.0,out x,out y);
167                 ng.SurfaceGravity(lat);
168                 ng.U(5000000.0,5000000.0,5000000.0,out x, out y, out z);
169                 ng.V0(5000000.0,5000000.0,5000000.0,out x, out y, out z);
170                 GravityCircle gc = gm.Circle(lat,0.0,GravityModel.Mask.ALL);
171                 gc.Capabilities();
172                 gc.Capabilities(GravityModel.Mask.GRAVITY);
173                 gc.Disturbance(lon, out x, out y, out z);
174                 gc.GeoidHeight(lon);
175                 gc.Gravity(lon, out x, out y, out z);
176                 gc.SphericalAnomaly(lon, out x, out y, out z);
177                 gc.T(lon);
178                 gc.V(lon, out x, out y, out z);
179                 gc.W(lon, out x, out y, out z);
180                 MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
181             }
182             catch (Exception xcpt)
183             {
184                 MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
185             }
186         }
187     }
188 }
189