public void GeodSolve17() { // Check fix for LONG_UNROLL bug found on 2015-05-07 GeodesicData dir = Geodesic.WGS84.Direct(40, -75, -10, 2e7, GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, -39, 1); AssertEquals(dir.lon2, -254, 1); AssertEquals(dir.azi2, -170, 1); GeodesicLine line = Geodesic.WGS84.Line(40, -75, -10); dir = line.Position(2e7, GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, -39, 1); AssertEquals(dir.lon2, -254, 1); AssertEquals(dir.azi2, -170, 1); dir = Geodesic.WGS84.Direct(40, -75, -10, 2e7); AssertEquals(dir.lat2, -39, 1); AssertEquals(dir.lon2, 105, 1); AssertEquals(dir.azi2, -170, 1); dir = line.Position(2e7); AssertEquals(dir.lat2, -39, 1); AssertEquals(dir.lon2, 105, 1); AssertEquals(dir.azi2, -170, 1); }
public void GeodSolve69() { // Check for InverseLine if line is slightly west of S and that s13 is // correctly set. GeodesicLine line = Geodesic.WGS84.InverseLine(-5, -0.000000000000002, -10, 180); GeodesicData dir = line.Position(2e7, GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, 4.96445, 0.5e-5); AssertEquals(dir.lon2, -180.00000, 0.5e-5); AssertEquals(dir.azi2, -0.00000, 0.5e-5); dir = line.Position(0.5 * line.Distance(), GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, -87.52461, 0.5e-5); AssertEquals(dir.lon2, -0.00000, 0.5e-5); AssertEquals(dir.azi2, -180.00000, 0.5e-5); }
public void GeodSolve71() { // Check that DirectLine sets s13. GeodesicLine line = Geodesic.WGS84.DirectLine(1, 2, 45, 1e7); GeodesicData dir = line.Position(0.5 * line.Distance(), GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, 30.92625, 0.5e-5); AssertEquals(dir.lon2, 37.54640, 0.5e-5); AssertEquals(dir.azi2, 55.43104, 0.5e-5); }
public void GeodSolve65() { // Check for bug in east-going check in GeodesicLine (needed to check for // sign of 0) and sign error in area calculation due to a bogus override // of the code for alp12. Found/fixed on 2015-12-19. GeodesicLine line = Geodesic.WGS84.InverseLine(30, -0.000000000000000001, -31, 180); GeodesicData dir = line.Position(1e7, GeodesicMask.ALL | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat1, 30.00000, 0.5e-5); AssertEquals(dir.lon1, -0.00000, 0.5e-5); AssertEquals(Math.Abs(dir.azi1), 180.00000, 0.5e-5); AssertEquals(dir.lat2, -60.23169, 0.5e-5); AssertEquals(dir.lon2, -0.00000, 0.5e-5); AssertEquals(Math.Abs(dir.azi2), 180.00000, 0.5e-5); AssertEquals(dir.s12, 10000000, 0.5); AssertEquals(dir.a12, 90.06544, 0.5e-5); AssertEquals(dir.m12, 6363636, 0.5); AssertEquals(dir.M12, -0.0012834, 0.5e7); AssertEquals(dir.M21, 0.0013749, 0.5e-7); AssertEquals(dir.S12, 0, 0.5); dir = line.Position(2e7, GeodesicMask.ALL | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat1, 30.00000, 0.5e-5); AssertEquals(dir.lon1, -0.00000, 0.5e-5); AssertEquals(Math.Abs(dir.azi1), 180.00000, 0.5e-5); AssertEquals(dir.lat2, -30.03547, 0.5e-5); AssertEquals(dir.lon2, -180.00000, 0.5e-5); AssertEquals(dir.azi2, -0.00000, 0.5e-5); AssertEquals(dir.s12, 20000000, 0.5); AssertEquals(dir.a12, 179.96459, 0.5e-5); AssertEquals(dir.m12, 54342, 0.5); AssertEquals(dir.M12, -1.0045592, 0.5e7); AssertEquals(dir.M21, -0.9954339, 0.5e-7); AssertEquals(dir.S12, 127516405431022.0, 0.5); }
public void GeodSolve61() { // Make sure small negative azimuths are west-going GeodesicData dir = Geodesic.WGS84.Direct(45, 0, -0.000000000000000003, 1e7, GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, 45.30632, 0.5e-5); AssertEquals(dir.lon2, -180, 0.5e-5); AssertEquals(Math.Abs(dir.azi2), 180, 0.5e-5); GeodesicLine line = Geodesic.WGS84.InverseLine(45, 0, 80, -0.000000000000000003); dir = line.Position(1e7, GeodesicMask.STANDARD | GeodesicMask.LONG_UNROLL); AssertEquals(dir.lat2, 45.30632, 0.5e-5); AssertEquals(dir.lon2, -180, 0.5e-5); AssertEquals(Math.Abs(dir.azi2), 180, 0.5e-5); }
static void Main(string[] args) { try { // Print waypoints between JFK and SIN Geodesic geod = new Geodesic(); // WGS84 double lat1 = 40.640, lon1 = -73.779, // JFK lat2 = 1.359, lon2 = 103.989; // SIN double s12, azi1, azi2, a12 = geod.Inverse(lat1, lon1, lat2, lon2, out s12, out azi1, out azi2); GeodesicLine line = new GeodesicLine(geod, lat1, lon1, azi1, Mask.ALL); // Alternatively GeodesicLine line = geod.Line(lat1, lon1, azi1, Mask.ALL); double ds = 500e3; // Nominal distance between points = 500 km int num = (int)(Math.Ceiling(s12 / ds)); // The number of intervals { // Use intervals of equal length ds = s12 / num; for (int i = 0; i <= num; ++i) { double lat, lon; line.Position(i * ds, out lat, out lon); Console.WriteLine(String.Format("i: {0} Latitude: {1} Longitude: {2}", i, lat, lon)); } } { // Slightly faster, use intervals of equal arc length double da = a12 / num; for (int i = 0; i <= num; ++i) { double lat, lon; line.ArcPosition(i * da, out lat, out lon); Console.WriteLine(String.Format("i: {0} Latitude: {1} Longitude: {2}", i, lat, lon)); } } } catch (GeographicErr e) { Console.WriteLine(String.Format("Caught exception: {0}", e.Message)); } }
// Gets the input parameters and calls the appropriate function private void OnForward(object sender, EventArgs e) { double origLatitude = 0.0, origLongitude = 0.0, origAzimuth = 0.0, distance = 0.0, finalLatitude = 0.0, finalLongitude = 0.0; // get & validate inputs try { if (m_function == Function.Direct) { distance = Double.Parse(m_variable == Variable.Distance ? m_distanceTextBox.Text : m_ArcLengthTextBox.Text); origAzimuth = Double.Parse(m_originAzimuthTextBox.Text); if (origAzimuth < -180.0 || origAzimuth > 180.0) { m_originAzimuthTextBox.Focus(); throw new Exception("Range Error: -180 <= initial azimuth <= 180 degrees"); } } else { finalLatitude = Double.Parse(m_finalLatitudeTextBox.Text); if (finalLatitude < -90.0 || finalLatitude > 90.0) { m_finalLatitudeTextBox.Focus(); throw new Exception("Range Error: -90 <= final latitude <= 90 degrees"); } finalLongitude = Double.Parse(m_finalLongitudeTextBox.Text); if (finalLongitude < -540.0 || finalLongitude > 540.0) { m_finalLongitudeTextBox.Focus(); throw new Exception("Range Error: -540 <= final longitude <= 540 degrees"); } } origLatitude = Double.Parse(m_originLatitudeTextBox.Text); if (origLatitude < -90.0 || origLatitude > 90.0) { m_originLatitudeTextBox.Focus(); throw new Exception("Range Error: -90 <= initial latitude <= 90 degrees"); } origLongitude = Double.Parse(m_originLongitudeTextBox.Text); if (origLongitude < -540.0 || origLongitude > 540.0) { m_originLongitudeTextBox.Focus(); throw new Exception("Range Error: -540 <= initial longitude <= 540 degrees"); } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, warning2, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // excute the appropriate function. double finalAzimuth = 0.0, reducedLength = 0.0, M12 = 0.0, M21 = 0.0, S12 = 0.0, arcDistance = 0.0; int sw = (int)m_function | (int)m_variable; if (sw == 3) { sw = 1; // cases 1 & 3 are identical. } try { switch (m_class) { case Classes.GEODESIC: switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = m_geodesic.Direct(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance m_ArcLengthTextBox.Text = m_geodesic.Inverse(origLatitude, origLongitude, finalLatitude, finalLongitude, out distance, out origAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_distanceTextBox.Text = distance.ToString(); m_originAzimuthTextBox.Text = origAzimuth.ToString(); break; case 2: // function == Direct, variable == arc length m_geodesic.ArcDirect(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; case Classes.GEODESICEXACT: GeodesicExact ge = new GeodesicExact(m_geodesic.MajorRadius, m_geodesic.Flattening); switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = ge.Direct(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance m_ArcLengthTextBox.Text = ge.Inverse(origLatitude, origLongitude, finalLatitude, finalLongitude, out distance, out origAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_distanceTextBox.Text = distance.ToString(); m_originAzimuthTextBox.Text = origAzimuth.ToString(); break; case 2: // function == Direct, variable == arc length ge.ArcDirect(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; case Classes.GEODESICLINE: GeodesicLine gl = new GeodesicLine(m_geodesic, origLatitude, origLongitude, origAzimuth, Mask.ALL); switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = gl.Position(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance throw new Exception("GeodesicLine does not have an Inverse function"); case 2: // function == Direct, variable == arc length gl.ArcPosition(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; case Classes.GEODESICLINEEXACT: GeodesicLineExact gle = new GeodesicLineExact(origLatitude, origLongitude, origAzimuth, Mask.ALL); switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = gle.Position(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance throw new Exception("GeodesicLineExact does not have an Inverse function"); case 2: // function == Direct, variable == arc length gle.ArcPosition(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; } } catch (Exception err) { MessageBox.Show(err.Message, warning, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// a simple validation function...does not change GUI elements private void OnValidate(object sender, EventArgs e) { double finalAzimuth = 0.0, reducedLength = 0.0, M12 = 0.0, M21 = 0.0, S12 = 0.0, arcDistance = 0.0, finalLatitude = 0.0, finalLongitude = 0.0, distance = 0.0; try { Geodesic g = new Geodesic(); g = new Geodesic(g.MajorRadius, g.Flattening); arcDistance = g.Direct(32.0, -86.0, 45.0, 20000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); double flat = 0.0, flon = 0.0, faz = 0.0, frd = 0.0, fm12 = 0.0, fm21 = 0.0, fs12 = 0.0, fad = 0.0; fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) { throw new Exception("Geodesic.Direct #1 failed"); } fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("Geodesic.Direct #2 failed"); } fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) { throw new Exception("Geodesic.Direct #3 failed"); } fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) { throw new Exception("Geodesic.Direct #4 failed"); } fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21) { throw new Exception("Geodesic.Direct #5 failed"); } double outd = 0.0; fad = g.GenDirect(32.0, -86.0, 45.0, false, 20000.0, Geodesic.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || outd != 20000.0 || fs12 != S12) { throw new Exception("Geodesic.GenDirect (false) failed"); } g.ArcDirect(32.0, -86.0, 45.0, 1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) { throw new Exception("Geodesic.ArcDirect #1 failed"); } g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("Geodesic.ArcDirect #2 failed"); } g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance) { throw new Exception("Geodesic.ArcDirect #3 failed"); } g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || frd != reducedLength) { throw new Exception("Geodesic.ArcDirect #4 failed"); } g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || fm12 != M12 || fm21 != M21) { throw new Exception("Geodesic.ArcDirect #5 failed"); } fad = g.GenDirect(32.0, -86.0, 45.0, true, 1.0, Geodesic.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (outd != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || fs12 != S12 || fad != 1.0) { throw new Exception("Geodesic.GenDirect (true) failed"); } double initAzimuth = 0.0, iaz = 0.0; arcDistance = g.Inverse(32.0, -86.0, 33.0, -87.0, out distance, out initAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd); if (fad != arcDistance || outd != distance) { throw new Exception("Geodesic.Inverse #1 failed"); } fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out iaz, out faz); if (fad != arcDistance || iaz != initAzimuth || faz != finalAzimuth) { throw new Exception("Geodesic.Inverse #2 failed"); } fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance) { throw new Exception("Geodesic.Inverse #3 failed"); } fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || frd != reducedLength) { throw new Exception("Geodesic.Inverse #4 failed"); } fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) { throw new Exception("Geodesic.Inverse #5 failed"); } fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) { throw new Exception("Geodesic.Inverse #6 failed"); } GeodesicLine gl = g.Line(32.0, -86.0, 45.0, Mask.ALL); gl = new GeodesicLine(32.0, -86.0, 45.0, Mask.ALL); gl = new GeodesicLine(g, 32.0, -86.0, 45.0, Mask.ALL); arcDistance = gl.Position(10000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = gl.Position(10000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) { throw new Exception("GeodesicLine.Position #1 failed"); } fad = gl.Position(10000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("GeodesicLine.Position #2 failed"); } fad = gl.Position(10000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) { throw new Exception("GeodesicLine.Position #3 failed"); } fad = gl.Position(10000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicLine.Position #4 failed"); } fad = gl.Position(10000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21 || frd != reducedLength) { throw new Exception("GeodesicLine.Position #5 failed"); } fad = gl.GenPosition(false, 10000.0, GeodesicLine.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != 10000.0 || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) { throw new Exception("GeodesicLine.GenPosition (false) failed"); } gl.ArcPosition(1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out distance, out reducedLength, out M12, out M21, out S12); gl.ArcPosition(1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) { throw new Exception("GeodesicLine.ArcPosition #1 failed"); } gl.ArcPosition(1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("GeodesicLine.ArcPosition #2 failed"); } gl.ArcPosition(1.0, out flat, out flon, out faz, out outd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance) { throw new Exception("GeodesicLine.ArcPosition #3 failed"); } gl.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || frd != reducedLength) { throw new Exception("GeodesicLine.ArcPosition #4 failed"); } gl.ArcPosition(1.0, out flat, out flon, out faz, out outd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicLine.ArcPosition #5 failed"); } gl.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) { throw new Exception("GeodesicLine.ArcPosition #6 failed"); } fad = gl.GenPosition(true, 1.0, GeodesicLine.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != 1.0 || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) { throw new Exception("GeodesicLine.GenPosition (false) failed"); } GeodesicExact ge = new GeodesicExact(); ge = new GeodesicExact(g.MajorRadius, g.Flattening); arcDistance = ge.Direct(32.0, -86.0, 45.0, 20000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) { throw new Exception("GeodesicExact.Direct #1 failed"); } fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("GeodesicExact.Direct #2 failed"); } fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) { throw new Exception("GeodesicExact.Direct #3 failed"); } fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicExact.Direct #4 failed"); } fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicExact.Direct #5 failed"); } fad = ge.GenDirect(32.0, -86.0, 45.0, false, 20000.0, GeodesicExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || outd != 20000.0 || fs12 != S12) { throw new Exception("GeodesicExact.GenDirect (false) failed"); } ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) { throw new Exception("GeodesicExact.ArcDirect #1 failed"); } ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("GeodesicExact.ArcDirect #2 failed"); } ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance) { throw new Exception("GeodesicExact.ArcDirect #3 failed"); } ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || frd != reducedLength) { throw new Exception("GeodesicExact.ArcDirect #4 failed"); } ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicExact.ArcDirect #5 failed"); } fad = ge.GenDirect(32.0, -86.0, 45.0, true, 1.0, GeodesicExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (outd != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || fad != 1.0 || fs12 != S12) { throw new Exception("GeodesicExact.GenDirect (true) failed"); } arcDistance = ge.Inverse(32.0, -86.0, 33.0, -87.0, out distance, out initAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd); if (fad != arcDistance || outd != distance) { throw new Exception("GeodesicExact.Inverse #1 failed"); } fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out iaz, out faz); if (fad != arcDistance || iaz != initAzimuth || faz != finalAzimuth) { throw new Exception("GeodesicExact.Inverse #2 failed"); } fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance) { throw new Exception("GeodesicExact.Inverse #3 failed"); } fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || frd != reducedLength) { throw new Exception("GeodesicExact.Inverse #4 failed"); } fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicExact.Inverse #5 failed"); } fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) { throw new Exception("GeodesicExact.Inverse #6 failed"); } GeodesicLineExact gle = ge.Line(32.0, -86.0, 45.0, Mask.ALL); gle = new GeodesicLineExact(32.0, -86.0, 45.0, Mask.ALL); gle = new GeodesicLineExact(ge, 32.0, -86.0, 45.0, Mask.ALL); arcDistance = gle.Position(10000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = gle.Position(10000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) { throw new Exception("GeodesicLineExact.Position #1 failed"); } fad = gle.Position(10000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("GeodesicLineExact.Position #2 failed"); } fad = gle.Position(10000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) { throw new Exception("GeodesicLineExact.Position #3 failed"); } fad = gle.Position(10000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicLineExact.Position #4 failed"); } fad = gle.Position(10000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21 || frd != reducedLength) { throw new Exception("GeodesicLineExact.Position #5 failed"); } fad = gle.GenPosition(false, 10000.0, GeodesicLineExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != 10000.0 || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) { throw new Exception("GeodesicLineExact.GenPosition (false) failed"); } gle.ArcPosition(1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out distance, out reducedLength, out M12, out M21, out S12); gle.ArcPosition(1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) { throw new Exception("GeodesicLineExact.ArcPosition #1 failed"); } gle.ArcPosition(1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) { throw new Exception("GeodesicLineExact.ArcPosition #2 failed"); } gle.ArcPosition(1.0, out flat, out flon, out faz, out outd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance) { throw new Exception("GeodesicLineExact.ArcPosition #3 failed"); } gle.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || frd != reducedLength) { throw new Exception("GeodesicLineExact.ArcPosition #4 failed"); } gle.ArcPosition(1.0, out flat, out flon, out faz, out outd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) { throw new Exception("GeodesicLineExact.ArcPosition #5 failed"); } gle.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) { throw new Exception("GeodesicLineExact.ArcPosition #6 failed"); } fad = gle.GenPosition(true, 1.0, GeodesicLineExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != 1.0 || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) { throw new Exception("GeodesicLineExact.GenPosition (false) failed"); } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Interface Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "Interfaces OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }
// a simple validation function...does not change GUI elements private void OnValidate(object sender, EventArgs e) { double finalAzimuth = 0.0, reducedLength = 0.0, M12 = 0.0, M21 = 0.0, S12 = 0.0, arcDistance = 0.0, finalLatitude = 0.0, finalLongitude = 0.0, distance = 0.0; try { Geodesic g = new Geodesic(); g = new Geodesic(g.MajorRadius, g.Flattening); arcDistance = g.Direct(32.0, -86.0, 45.0, 20000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); double flat = 0.0, flon = 0.0, faz = 0.0, frd = 0.0, fm12 = 0.0, fm21 = 0.0, fs12 = 0.0, fad = 0.0; fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) throw new Exception("Geodesic.Direct #1 failed"); fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("Geodesic.Direct #2 failed"); fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) throw new Exception("Geodesic.Direct #3 failed"); fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) throw new Exception("Geodesic.Direct #4 failed"); fad = g.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21) throw new Exception("Geodesic.Direct #5 failed"); double outd = 0.0; fad = g.GenDirect(32.0, -86.0, 45.0, false, 20000.0, Geodesic.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || outd != 20000.0 || fs12 != S12) throw new Exception("Geodesic.GenDirect (false) failed"); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) throw new Exception("Geodesic.ArcDirect #1 failed"); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("Geodesic.ArcDirect #2 failed"); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance) throw new Exception("Geodesic.ArcDirect #3 failed"); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || frd != reducedLength) throw new Exception("Geodesic.ArcDirect #4 failed"); g.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || fm12 != M12 || fm21 != M21) throw new Exception("Geodesic.ArcDirect #5 failed"); fad = g.GenDirect(32.0, -86.0, 45.0, true, 1.0, Geodesic.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (outd != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || fs12 != S12 || fad != 1.0) throw new Exception("Geodesic.GenDirect (true) failed"); double initAzimuth = 0.0, iaz = 0.0; arcDistance = g.Inverse(32.0, -86.0, 33.0, -87.0, out distance, out initAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd); if (fad != arcDistance || outd != distance) throw new Exception("Geodesic.Inverse #1 failed"); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out iaz, out faz); if (fad != arcDistance || iaz != initAzimuth || faz != finalAzimuth) throw new Exception("Geodesic.Inverse #2 failed"); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance) throw new Exception("Geodesic.Inverse #3 failed"); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || frd != reducedLength) throw new Exception("Geodesic.Inverse #4 failed"); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out fm12, out fm21 ); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 ) throw new Exception("Geodesic.Inverse #5 failed"); fad = g.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) throw new Exception("Geodesic.Inverse #6 failed"); GeodesicLine gl = g.Line(32.0, -86.0, 45.0, Mask.ALL); gl = new GeodesicLine(32.0, -86.0, 45.0, Mask.ALL); gl = new GeodesicLine(g, 32.0, -86.0, 45.0, Mask.ALL); arcDistance = gl.Position(10000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = gl.Position(10000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) throw new Exception("GeodesicLine.Position #1 failed"); fad = gl.Position(10000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("GeodesicLine.Position #2 failed"); fad = gl.Position(10000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) throw new Exception("GeodesicLine.Position #3 failed"); fad = gl.Position(10000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicLine.Position #4 failed"); fad = gl.Position(10000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21 || frd != reducedLength ) throw new Exception("GeodesicLine.Position #5 failed"); fad = gl.GenPosition(false, 10000.0, GeodesicLine.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != 10000.0 || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12 ) throw new Exception("GeodesicLine.GenPosition (false) failed"); gl.ArcPosition(1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out distance, out reducedLength, out M12, out M21, out S12); gl.ArcPosition(1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) throw new Exception("GeodesicLine.ArcPosition #1 failed"); gl.ArcPosition(1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("GeodesicLine.ArcPosition #2 failed"); gl.ArcPosition(1.0, out flat, out flon, out faz, out outd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance) throw new Exception("GeodesicLine.ArcPosition #3 failed"); gl.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || frd != reducedLength) throw new Exception("GeodesicLine.ArcPosition #4 failed"); gl.ArcPosition(1.0, out flat, out flon, out faz, out outd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicLine.ArcPosition #5 failed"); gl.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) throw new Exception("GeodesicLine.ArcPosition #6 failed"); fad = gl.GenPosition(true, 1.0, GeodesicLine.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != 1.0 || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) throw new Exception("GeodesicLine.GenPosition (false) failed"); GeodesicExact ge = new GeodesicExact(); ge = new GeodesicExact(g.MajorRadius, g.Flattening); arcDistance = ge.Direct(32.0, -86.0, 45.0, 20000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) throw new Exception("GeodesicExact.Direct #1 failed"); fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("GeodesicExact.Direct #2 failed"); fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) throw new Exception("GeodesicExact.Direct #3 failed"); fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicExact.Direct #4 failed"); fad = ge.Direct(32.0, -86.0, 45.0, 20000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicExact.Direct #5 failed"); fad = ge.GenDirect(32.0, -86.0, 45.0, false, 20000.0, GeodesicExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || outd != 20000.0 || fs12 != S12) throw new Exception("GeodesicExact.GenDirect (false) failed"); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) throw new Exception("GeodesicExact.ArcDirect #1 failed"); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("GeodesicExact.ArcDirect #2 failed"); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance) throw new Exception("GeodesicExact.ArcDirect #3 failed"); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || frd != reducedLength) throw new Exception("GeodesicExact.ArcDirect #4 failed"); ge.ArcDirect(32.0, -86.0, 45.0, 1.0, out flat, out flon, out faz, out fad, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fad != arcDistance || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicExact.ArcDirect #5 failed"); fad = ge.GenDirect(32.0, -86.0, 45.0, true, 1.0, GeodesicExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (outd != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength || fm12 != M12 || fm21 != M21 || fad != 1.0 || fs12 != S12) throw new Exception("GeodesicExact.GenDirect (true) failed"); arcDistance = ge.Inverse(32.0, -86.0, 33.0, -87.0, out distance, out initAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd); if (fad != arcDistance || outd != distance) throw new Exception("GeodesicExact.Inverse #1 failed"); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out iaz, out faz); if (fad != arcDistance || iaz != initAzimuth || faz != finalAzimuth) throw new Exception("GeodesicExact.Inverse #2 failed"); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance) throw new Exception("GeodesicExact.Inverse #3 failed"); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || frd != reducedLength) throw new Exception("GeodesicExact.Inverse #4 failed"); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicExact.Inverse #5 failed"); fad = ge.Inverse(32.0, -86.0, 33.0, -87.0, out outd, out iaz, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || outd != distance || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) throw new Exception("GeodesicExact.Inverse #6 failed"); GeodesicLineExact gle = ge.Line(32.0, -86.0, 45.0, Mask.ALL); gle = new GeodesicLineExact(32.0, -86.0, 45.0, Mask.ALL); gle = new GeodesicLineExact(ge, 32.0, -86.0, 45.0, Mask.ALL); arcDistance = gle.Position(10000.0, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12); fad = gle.Position(10000.0, out flat, out flon); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude) throw new Exception("GeodesicLineExact.Position #1 failed"); fad = gle.Position(10000.0, out flat, out flon, out faz); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("GeodesicLineExact.Position #2 failed"); fad = gle.Position(10000.0, out flat, out flon, out faz, out frd); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || frd != reducedLength) throw new Exception("GeodesicLineExact.Position #3 failed"); fad = gle.Position(10000.0, out flat, out flon, out faz, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicLineExact.Position #4 failed"); fad = gle.Position(10000.0, out flat, out flon, out faz, out frd, out fm12, out fm21); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || fm12 != M12 || fm21 != M21 || frd != reducedLength) throw new Exception("GeodesicLineExact.Position #5 failed"); fad = gle.GenPosition(false, 10000.0, GeodesicLineExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != arcDistance || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != 10000.0 || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) throw new Exception("GeodesicLineExact.GenPosition (false) failed"); gle.ArcPosition(1.0, out finalLatitude, out finalLongitude, out finalAzimuth, out distance, out reducedLength, out M12, out M21, out S12); gle.ArcPosition(1.0, out flat, out flon); if (flat != finalLatitude || flon != finalLongitude) throw new Exception("GeodesicLineExact.ArcPosition #1 failed"); gle.ArcPosition(1.0, out flat, out flon, out faz); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth) throw new Exception("GeodesicLineExact.ArcPosition #2 failed"); gle.ArcPosition(1.0, out flat, out flon, out faz, out outd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance) throw new Exception("GeodesicLineExact.ArcPosition #3 failed"); gle.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || frd != reducedLength) throw new Exception("GeodesicLineExact.ArcPosition #4 failed"); gle.ArcPosition(1.0, out flat, out flon, out faz, out outd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21) throw new Exception("GeodesicLineExact.ArcPosition #5 failed"); gle.ArcPosition(1.0, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21); if (flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength) throw new Exception("GeodesicLineExact.ArcPosition #6 failed"); fad = gle.GenPosition(true, 1.0, GeodesicLineExact.mask.ALL, out flat, out flon, out faz, out outd, out frd, out fm12, out fm21, out fs12); if (fad != 1.0 || flat != finalLatitude || flon != finalLongitude || faz != finalAzimuth || outd != distance || fm12 != M12 || fm21 != M21 || frd != reducedLength || fs12 != S12) throw new Exception("GeodesicLineExact.GenPosition (false) failed"); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Interface Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "Interfaces OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }
// Gets the input parameters and calls the appropriate function private void OnForward(object sender, EventArgs e) { double origLatitude = 0.0, origLongitude = 0.0, origAzimuth = 0.0, distance = 0.0, finalLatitude = 0.0, finalLongitude = 0.0; // get & validate inputs try { if ( m_function == Function.Direct ) { distance = Double.Parse( m_variable == Variable.Distance ? m_distanceTextBox.Text : m_ArcLengthTextBox.Text ); origAzimuth = Double.Parse( m_originAzimuthTextBox.Text ); if ( origAzimuth < -180.0 || origAzimuth > 180.0 ) { m_originAzimuthTextBox.Focus(); throw new Exception( "Range Error: -180 <= initial azimuth <= 180 degrees" ); } } else { finalLatitude = Double.Parse( m_finalLatitudeTextBox.Text ); if (finalLatitude < -90.0 || finalLatitude > 90.0) { m_finalLatitudeTextBox.Focus(); throw new Exception("Range Error: -90 <= final latitude <= 90 degrees"); } finalLongitude = Double.Parse( m_finalLongitudeTextBox.Text ); if (finalLongitude < -540.0 || finalLongitude > 540.0) { m_finalLongitudeTextBox.Focus(); throw new Exception("Range Error: -540 <= final longitude <= 540 degrees"); } } origLatitude = Double.Parse( m_originLatitudeTextBox.Text ); if (origLatitude < -90.0 || origLatitude > 90.0) { m_originLatitudeTextBox.Focus(); throw new Exception("Range Error: -90 <= initial latitude <= 90 degrees"); } origLongitude = Double.Parse(m_originLongitudeTextBox.Text); if (origLongitude < -540.0 || origLongitude > 540.0) { m_originLongitudeTextBox.Focus(); throw new Exception("Range Error: -540 <= initial longitude <= 540 degrees"); } } catch ( Exception xcpt ) { MessageBox.Show(xcpt.Message, warning2, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // excute the appropriate function. double finalAzimuth = 0.0, reducedLength = 0.0, M12 = 0.0, M21 = 0.0, S12 = 0.0, arcDistance = 0.0; int sw = (int)m_function | (int)m_variable; if (sw == 3) sw = 1; // cases 1 & 3 are identical. try { switch (m_class) { case Classes.GEODESIC: switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = m_geodesic.Direct(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance m_ArcLengthTextBox.Text = m_geodesic.Inverse(origLatitude, origLongitude, finalLatitude, finalLongitude, out distance, out origAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_distanceTextBox.Text = distance.ToString(); m_originAzimuthTextBox.Text = origAzimuth.ToString(); break; case 2: // function == Direct, variable == arc length m_geodesic.ArcDirect(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; case Classes.GEODESICEXACT: GeodesicExact ge = new GeodesicExact(m_geodesic.MajorRadius, m_geodesic.Flattening); switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = ge.Direct(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance m_ArcLengthTextBox.Text = ge.Inverse(origLatitude, origLongitude, finalLatitude, finalLongitude, out distance, out origAzimuth, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_distanceTextBox.Text = distance.ToString(); m_originAzimuthTextBox.Text = origAzimuth.ToString(); break; case 2: // function == Direct, variable == arc length ge.ArcDirect(origLatitude, origLongitude, origAzimuth, distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; case Classes.GEODESICLINE: GeodesicLine gl = new GeodesicLine(m_geodesic, origLatitude, origLongitude, origAzimuth, Mask.ALL); switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = gl.Position(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance throw new Exception("GeodesicLine does not have an Inverse function"); case 2: // function == Direct, variable == arc length gl.ArcPosition(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; case Classes.GEODESICLINEEXACT: GeodesicLineExact gle = new GeodesicLineExact(origLatitude, origLongitude, origAzimuth, Mask.ALL); switch (sw) { case 0: // function == Direct, variable == distance m_ArcLengthTextBox.Text = gle.Position(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out reducedLength, out M12, out M21, out S12).ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; case 1: // function == Inverse, variable == distance throw new Exception("GeodesicLineExact does not have an Inverse function"); case 2: // function == Direct, variable == arc length gle.ArcPosition(distance, out finalLatitude, out finalLongitude, out finalAzimuth, out arcDistance, out reducedLength, out M12, out M21, out S12); m_distanceTextBox.Text = arcDistance.ToString(); m_finalLatitudeTextBox.Text = finalLatitude.ToString(); m_finalLongitudeTextBox.Text = finalLongitude.ToString(); break; } m_finalAzimuthTextBox.Text = finalAzimuth.ToString(); m_reducedLengthTextBox.Text = reducedLength.ToString(); m_M12TextBox.Text = M12.ToString(); m_M21TextBox.Text = M21.ToString(); m_S12TextBox.Text = S12.ToString(); break; } } catch (Exception err) { MessageBox.Show(err.Message, warning, MessageBoxButtons.OK, MessageBoxIcon.Error); } }