private void OnValidate(object sender, EventArgs e) { try { Geocentric g = new Geocentric(); string test = g.ToString(); g = new Geocentric(g.MajorRadius, g.Flattening); double x, y, z, lat, lon, alt, tx, ty, tz; double[,] rot; g.Forward(32.0, -86.0, 45.0, out x, out y, out z, out rot); g.Forward(32.0, -86.0, 45.0, out tx, out ty, out tz); if (x != tx || y != ty || z != tz) { throw new Exception("Error in Forward"); } g.Reverse(x, y, z, out lat, out lon, out alt, out rot); g.Reverse(x, y, z, out tx, out ty, out tz); if (lat != tx || lon != ty || alt != tz) { throw new Exception("Error in Reverse"); } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error detected", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }
static void Main(string[] args) { try { Geocentric earth = new Geocentric(Constants.WGS84.MajorRadius, Constants.WGS84.Flattening); // Alternatively: Geocentric earth = new Geocentric(); { // Sample forward calculation double lat = 27.99, lon = 86.93, h = 8820; // Mt Everest double X, Y, Z; earth.Forward(lat, lon, h, out X, out Y, out Z); Console.WriteLine(String.Format("{0} {1} {2}", Math.Floor(X / 1000 + 0.5), Math.Floor(Y / 1000 + 0.5), Math.Floor(Z / 1000 + 0.5))); } { // Sample reverse calculation double X = 302e3, Y = 5636e3, Z = 2980e3; double lat, lon, h; earth.Reverse(X, Y, Z, out lat, out lon, out h); Console.WriteLine(String.Format("{0} {1} {2}", lat, lon, h)); } } catch (GeographicErr e) { Console.WriteLine(String.Format("Caught exception: {0}", e.Message)); } }
static void Main(string[] args) { try { Geocentric earth = new Geocentric( Constants.WGS84.MajorRadius, Constants.WGS84.Flattening); // Alternatively: Geocentric earth = new Geocentric(); { // Sample forward calculation double lat = 27.99, lon = 86.93, h = 8820; // Mt Everest double X, Y, Z; earth.Forward(lat, lon, h, out X, out Y, out Z); Console.WriteLine( String.Format( "{0} {1} {2}", Math.Floor(X / 1000 + 0.5), Math.Floor(Y / 1000 + 0.5), Math.Floor(Z / 1000 + 0.5) ) ); } { // Sample reverse calculation double X = 302e3, Y = 5636e3, Z = 2980e3; double lat, lon, h; earth.Reverse(X, Y, Z, out lat, out lon, out h); Console.WriteLine(String.Format("{0} {1} {2}", lat, lon, h)); } } catch (GeographicErr e) { Console.WriteLine( String.Format( "Caught exception: {0}", e.Message ) ); } }
private void OnConvert(object sender, EventArgs e) { try { double lat, lon, alt, x, y, z; double[,] rot = null; switch (m_function) { case Functions.Forward: lat = Double.Parse(m_latitudeTextBox.Text); lon = Double.Parse(m_longitudeTextBox.Text); alt = Double.Parse(m_altitudeTextBox.Text); m_geocentric.Forward(lat, lon, alt, out x, out y, out z, out rot); m_XTextBox.Text = x.ToString(); m_YTextBox.Text = y.ToString(); m_ZTextBox.Text = z.ToString(); break; case Functions.Inverse: x = Double.Parse(m_XTextBox.Text); y = Double.Parse(m_YTextBox.Text); z = Double.Parse(m_ZTextBox.Text); m_geocentric.Reverse(x, y, z, out lat, out lon, out alt, out rot); m_latitudeTextBox.Text = lat.ToString(); m_longitudeTextBox.Text = lon.ToString(); m_altitudeTextBox.Text = alt.ToString(); break; } m_textBox00.Text = rot[0, 0].ToString(); m_textBox01.Text = rot[0, 1].ToString(); m_textBox02.Text = rot[0, 2].ToString(); m_textBox10.Text = rot[1, 0].ToString(); m_textBox11.Text = rot[1, 1].ToString(); m_textBox12.Text = rot[1, 2].ToString(); m_textBox20.Text = rot[2, 0].ToString(); m_textBox21.Text = rot[2, 1].ToString(); m_textBox22.Text = rot[2, 2].ToString(); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnValidate(object sender, EventArgs e) { try { Geocentric g = new Geocentric(); string test = g.ToString(); g = new Geocentric(g.MajorRadius, g.Flattening); double x, y, z, lat, lon, alt, tx, ty, tz; double[,] rot; g.Forward(32.0, -86.0, 45.0, out x, out y, out z, out rot); g.Forward(32.0, -86.0, 45.0, out tx, out ty, out tz); if (x != tx || y != ty || z != tz) throw new Exception("Error in Forward"); g.Reverse(x, y, z, out lat, out lon, out alt, out rot); g.Reverse(x, y, z, out tx, out ty, out tz); if ( lat != tx || lon != ty || alt != tz ) throw new Exception("Error in Reverse"); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error detected", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }