September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,28 +1,33 @@
|
|||
import Text.Printf
|
||||
import Control.Arrow ((***))
|
||||
|
||||
-- The haversine of an angle.
|
||||
hsin t = let u = sin (t/2) in u*u
|
||||
|
||||
-- The distance between two points, given by latitude and longtitude, on a
|
||||
-- circle. The points are specified in radians.
|
||||
distRad radius (lat1, lng1) (lat2, lng2) =
|
||||
let hlat = hsin (lat2 - lat1)
|
||||
hlng = hsin (lng2 - lng1)
|
||||
root = sqrt (hlat + cos lat1 * cos lat2 * hlng)
|
||||
in 2 * radius * asin (min 1.0 root)
|
||||
|
||||
-- The distance between two points, given by latitude and longtitude, on a
|
||||
-- circle. The points are specified in degrees.
|
||||
distDeg radius p1 p2 = distRad radius (deg2rad p1) (deg2rad p2)
|
||||
where deg2rad (t, u) = (d2r t, d2r u)
|
||||
d2r t = t * pi / 180
|
||||
haversine :: Float -> Float
|
||||
haversine = (^ 2) . sin . (/ 2)
|
||||
|
||||
-- The approximate distance, in kilometers, between two points on Earth.
|
||||
-- The latitude and longtitude are assumed to be in degrees.
|
||||
earthDist = distDeg 6372.8
|
||||
earthDist :: (Float, Float) -> (Float, Float) -> Float
|
||||
earthDist = distDeg 6371
|
||||
where
|
||||
distDeg radius p1 p2 = distRad radius (deg2rad p1) (deg2rad p2)
|
||||
distRad radius (lat1, lng1) (lat2, lng2) =
|
||||
(2 * radius) *
|
||||
asin
|
||||
(min
|
||||
1.0
|
||||
(sqrt $
|
||||
haversine (lat2 - lat1) +
|
||||
((cos lat1 * cos lat2) * haversine (lng2 - lng1))))
|
||||
deg2rad = d2r *** d2r
|
||||
where
|
||||
d2r = (/ 180) . (pi *)
|
||||
|
||||
main = do
|
||||
let bna = (36.12, -86.67)
|
||||
lax = (33.94, -118.40)
|
||||
dst = earthDist bna lax :: Double
|
||||
printf "The distance between BNA and LAX is about %0.f km.\n" dst
|
||||
main :: IO ()
|
||||
main =
|
||||
printf
|
||||
"The distance between BNA and LAX is about %0.f km.\n"
|
||||
(earthDist bna lax)
|
||||
where
|
||||
bna = (36.12, -86.67)
|
||||
lax = (33.94, -118.40)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue