LazMapViewer: Fix floating point error in HaversineAngle. In CalcIntermedPoint, use length units specification in CalcGeoDistance rather than multiplying result by 1000.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9576 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2025-01-09 21:48:48 +00:00
parent b361823008
commit aed26fd17b

View File

@ -76,7 +76,7 @@ end;
function HaversineAngle(Lat1, Lon1, Lat2, Lon2: Double): Double;
var
latFrom, latTo, lonDiff: Double;
dx, dy, dz: Double;
dx, dy, dz, arg: Double;
begin
lonDiff := Lon1 - Lon2;
latFrom := Lat1;
@ -86,7 +86,14 @@ begin
dx := cos(lonDiff) * cos(latFrom) - cos(latTo);
dy := sin(lonDiff) * cos(latFrom);
Result := arcsin(sqrt(sqr(dx) + sqr(dy) + sqr(dz)) / 2.0) * 2.0;
arg := sqrt(sqr(dx) + sqr(dy) + sqr(dz)) / 2.0;
if arg >= 1.0 then
Result := pi
else
if arg <= -1.0 then
Result := -pi
else
Result := arcsin(arg) * 2.0;
end;
// Angles in degrees
@ -233,7 +240,7 @@ begin
Lon := Lon2;
Exit;
end;
aD := CalcGeoDistance(Lat1, Lon1, Lat2, Lon2) / EARTH_EQUATORIAL_RADIUS;
aD := CalcGeoDistance(Lat1, Lon1, Lat2, Lon2, duMeters) / EARTH_EQUATORIAL_RADIUS;
latFrom := DegToRad(Lat1);
lonFrom := DegToRad(Lon1);
latTo := DegToRad(Lat2);