-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimized-distance.lisp
More file actions
32 lines (29 loc) · 1.22 KB
/
optimized-distance.lisp
File metadata and controls
32 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(defvar *earth-radius* (the fixnum 6371))
(defun degree-to-radian (deg)
(declare (type single-float deg)
(optimize (speed 3) (safety 0) (debug 0)))
(the single-float (* deg (/ (coerce pi 'single-float) 180))))
(defun distance (lata lnga latb lngb)
(declare (type single-float lata lnga latb lngb)
(optimize (speed 3) (safety 0) (debug 0)))
(let* ((lata-r (the single-float (degree-to-radian lata)))
(lnga-r (the single-float (degree-to-radian lnga)))
(latb-r (the single-float (degree-to-radian latb)))
(lngb-r (the single-float (degree-to-radian lngb)))
(delta-lat (the single-float (- latb-r lata-r)))
(delta-lng (the single-float (- lngb-r lnga-r))))
(* (the fixnum (* (the fixnum *earth-radius*)
2))
(the single-float
(asin (the single-float
(sqrt (+ (expt (sin (/ delta-lat 2)) 2)
(* (cos lata-r)
(cos latb-r)
(expt (sin (/ delta-lng 2)) 2))))))))))
(defun test ()
(let ((increment 2.5))
(time (loop for lata from -90.0 to 90.0 by increment do
(loop for lnga from -180.0 to 180.0 by increment do
(loop for latb from -90.0 to 90.0 by increment do
(loop for lngb from -180.0 to 180.0 by increment do
(distance lata lnga latb lngb))))))))