You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got different results because your code is different from that from the book:
(defwalking-speed4)
Book says:
... and an average of walking speed of 5 km per hour.
(defndistance"Returns a rough estimate of the distance between two coordinate points, in kilometers. Works better with smaller distance"
[{lat1 :lat lon1 :lon} {lat2 :lat lon2 :lon}]
(let [deglen 110.25
x (- lat2 lat1)
y (* (Math/cos lat2) (- lon2 lon1))]
(* deglen (Math/sqrt (+ (* y y) (* x x))))))
Roberto, you only identified the smallest problem with this terrible code. Yes, they switched from cos(lat1) to cos(lat2). But they shouldn't be computing cos() of either. Java's Math.cos() method takes radian arguments, not degrees of latitude. You have to first call Math.toRadians(): Math.cos(Math.toRadians(lat1))
Furthermore, they are squaring the cos() factor in (* y y) above, so the result is (cos(lat2)*(lon2-lon1))^2 not what the formula in the book shows at all...
I got different results because your code is different from that from the book:
Book says:
Book has:
Please notice that has cos(lat1) not cos(lat2)
The text was updated successfully, but these errors were encountered: