This question is building on Difference (angle) between two bearings.
Basically, if we can find the difference between two bearings, can we find the side on which the object needs to turn to achieve the smallest amount of rotation.
Using the solution/function in R, from the previous question:
angle_diff <- function(ber1, ber2){
theta <- abs(ber1 - ber2) %% 360
return(ifelse(theta > 180, 360 - theta, theta))
}
To show what is needed here are 2 examples:
First ex.: if we have ber1
= - 175 and ber2
= 175, in order for the object to go from bearing -175 to bearing 175 it needs to turn counter clockwise for 10 degrees.
Second ex.: if we have ber1
= - 10 and ber2
= 50, in order for the object to go from bearing -10 to bearing 50 it needs to turn clockwise for 60 degrees.
Finding the amount of degrees to make the shortest term is answered in the question mentioned above, but is it possible to find whether the turn needs to be made clockwise or counter clockwise ?
Perhaps something like this?
bearing_diff <- function(b1, b2) {
angle <- b2 - b1
clockwise <- angle %% 360
counter_clockwise <- 360 - clockwise
if(abs(clockwise) < abs(counter_clockwise)) {
paste(abs(clockwise), "degrees clockwise")
} else {
paste(abs(counter_clockwise), "degrees counter-clockwise")
}
}
bearing_diff(175, -175)
#> [1] "10 degrees clockwise"
bearing_diff(0, 180)
#> [1] "180 degrees counter-clockwise"
bearing_diff(0, 185)
#> [1] "175 degrees counter-clockwise"
Created on 2020-08-15 by the reprex package (v0.3.0)