Difference (angle) between two bearings

蹲街弑〆低调 提交于 2021-02-10 06:27:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!