Isoraqathedh

Great-Circle-Distance implement

Jan 7th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defun great-circle-distance (from-longitude from-latitude to-longitude to-latitude)
  2.   (let ((Earth-radius 6371))
  3.        (* 2
  4.           Earth-radius
  5.           (asin (min (sqrt (* (expt (sin (/ (- to-latitude  from-latitude ) 2)) 2)
  6.                               (expt (sin (/ (- to-longitude from-longitude) 2)) 2)
  7.                               (cos to-latitude)))
  8.                  1)))))
  9.  
  10. (defun transport-time (distance)
  11.   (flet ((format-and-print (divisor transport-method)
  12.            (format NIL "Human terms: ~a away by ~a, using an average speed of ~a km/h."
  13.                    (/ distance divisor) transport-method divisor)))
  14.     (cond
  15.      ((< distance 0))
  16.      ((< distance 150)
  17.       (format-and-print 50 "car"))
  18.      ((< distance 2500)
  19.       (format-and-print 130 "train"))
  20.      ((< distance 12500)
  21.       (format-and-print 800 "plane"))
  22.      (T
  23.       (format-and-print 18000 "ICBM")))))
  24.  
  25. (multiple-value-bind (from-latitude from-longitude) (coordinates place1)
  26.   (multiple-value-bind (to-latitude to-longitude) (coordinates place2)
  27.     (let ((distance) (great-circle-distance from-longitude from-latitude to-longitude to-latitude))
  28.          (format NIL "Distance: ~a km" distance)
  29.          (transport-time distance))))
Advertisement
Add Comment
Please, Sign In to add comment