【问题标题】:r - find the side of turning to achieve smallest angle between two bearingsr - 找到转动的一侧以实现两个轴承之间的最小角度
【发布时间】:2020-08-15 18:11:00
【问题描述】:

此问题基于Difference (angle) between two bearings

基本上,如果我们能找到两个轴承之间的差异,我们是否可以找到物体需要转动的一侧才能实现最小的旋转量。

使用 R 中的解决方案/函数,来自上一个问题:

angle_diff <- function(ber1, ber2){
  theta <- abs(ber1 - ber2) %% 360 
  return(ifelse(theta > 180, 360 - theta, theta))
  }

为了说明这里需要的是 2 个示例:

第一个例子:如果我们有 ber1 = - 175 和 ber2 = 175,为了让物体从轴承 -175 转到轴承 175,它需要逆时针旋转 10度。

第二个例子:如果我们有 ber1 = - 10 和 ber2 = 50,为了让物体从轴承 -10 转到轴承 50,它需要 顺时针 转动60度。

上面提到的问题回答了求最短项的度数,但是是否有可能找到需要顺时针还是逆时针转弯?

【问题讨论】:

    标签: r bearing


    【解决方案1】:

    也许是这样的?

    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"
    

    reprex package (v0.3.0) 于 2020-08-15 创建

    【讨论】:

      猜你喜欢
      • 2013-04-17
      • 2018-11-10
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多