问题
Using geosphere::bearing
I can calculate the bearing of two lines, but is it possible to calculate the angle between the two bearings ?
Of course you can try and subtract or sum up the bearings but in specific cases where one is negative and the other is positive this doesn't work.
For example if the ber1
= - 175 and ber2
= 175 the angle between should be 10.
Any suggestions ?
回答1:
I am not sure of a ready-made package but in case you are interested in a solution then you can try
angle_diff <- function(theta1, theta2){
theta <- abs(theta1 - theta2) %% 360
return(ifelse(theta > 180, 360 - theta, theta))
}
which gives the angle between your example bearings -175 & 175 as
angle_diff(-175, 175)
#[1] 10
来源:https://stackoverflow.com/questions/50623304/difference-angle-between-two-bearings