geotools-devel

 [Geotools-devel] [jira] Created: (GEOT-3826) Geodetic calculator returns wrong value for distance from (0, 0) to (0, 90) From: Mike Dixon (JIRA) - 2011-08-26 18:31:39 ```Geodetic calculator returns wrong value for distance from (0, 0) to (0, 90) --------------------------------------------------------------------------- Key: GEOT-3826 URL: https://jira.codehaus.org/browse/GEOT-3826 Project: GeoTools Issue Type: Bug Components: referencing Affects Versions: 2.7.1 Reporter: Mike Dixon Assignee: Andrea Aime Priority: Minor GeodeticCalculator gc = new GeodeticCalculator(); gc.setStartingGeographicPoint(0, 0); gc.setDestinationGeographicPoint(0, 90); System.out.println(gc.getOrthodromicDistance()); returns the wrong value (it prints 2e7, instead of 1e7). the bug appears to be an error in the translation of getMeridianArcLengthRadians() from the original fortran; the variable S2 isn't reset to 0 after being temporarily used store abs(p2), so if the if () isn't taken it still has that value instead of the 0 expected by the original code. (it's unclear why that if() is there at all; the excluded code works fine for (0, pi/2). if it's there as an optimization it's and odd choice, since it doesn't catch the equivalent case of (pi/2, 0).) i think the cleanest fix would be to just simplify the code a little: double S2 = 0; // Check for a 90 degree lookup if (abs(P1) > TOLERANCE_0 || abs(abs(P2) - PI/2) > TOLERANCE_0) { final double DB = sin(P2* 2.0) - sin(P1* 2.0); final double DC = sin(P2* 4.0) - sin(P1* 4.0); final double DD = sin(P2* 6.0) - sin(P1* 6.0); final double DE = sin(P2* 8.0) - sin(P1* 8.0); final double DF = sin(P2*10.0) - sin(P1*10.0); // Compute the S2 part of the series expansion S2 = -DB*B/2.0 + DC*C/4.0 - DD*D/6.0 + DE*E/8.0 - DF*F/10.0; } // Compute the S1 part of the series expansion double S1 = (P2-P1) * A; ... -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira ```