Haversine formula: Difference between revisions

no edit summary
m (Added Sidef language)
No edit summary
Line 842:
{{out}}
<pre>2.8872599506071115e+03</pre>
 
=={{header|Oberon-2}}==
Works with oo2c version2
<lang oberon2>
MODULE Haversines;
IMPORT
LRealMath,
Out;
PROCEDURE Distance(lat1,lon1,lat2,lon2: LONGREAL): LONGREAL;
CONST
r = 6372.8D0; (* Earth radius as LONGREAL *)
to_radians = LRealMath.pi / 180.0D0;
VAR
d,ph1,th1,th2: LONGREAL;
dz,dx,dy: LONGREAL;
BEGIN
d := lon1 - lon2;
ph1 := d * to_radians;
th1 := lat1 * to_radians;
th2 := lat2 * to_radians;
dz := LRealMath.sin(th1) - LRealMath.sin(th2);
dx := LRealMath.cos(ph1) * LRealMath.cos(th1) - LRealMath.cos(th2);
dy := LRealMath.sin(ph1) * LRealMath.cos(th1);
RETURN LRealMath.arcsin(LRealMath.sqrt(LRealMath.power(dx,2.0) + LRealMath.power(dy,2.0) + LRealMath.power(dz,2.0)) / 2.0) * 2.0 * r;
END Distance;
BEGIN
Out.LongRealFix(Distance(36.12,-86.67,33.94,-118.4),6,10);Out.Ln
END Haversines.
</lang>
Output:
<pre>
2887.2602975600
</pre>
 
=={{header|Objeck}}==
Anonymous user