根据角度找到正确的车轮段

发布于 2025-01-18 12:48:18 字数 361 浏览 3 评论 0原文

输入图片此处描述

在此场景中,角度 0 表示最小索引 (0) 和最大索引 (7) 之间的线段在圆的右半部分(左侧图像)上是水平的。在中间图像中,车轮已旋转 23 度。这里,正确答案 (x) 是 3,因为黄色指针位于索引 3 处的线段上。在右图中,轮盘已旋转 220 度,正确答案 (x) 是 7。

在此轮盘中,n = 8。有 8 个段。角度 (a) 是车轮从其原始位置旋转的距离。

那么给定 n 和 a,你将如何计算 x?

enter image description here

In this scenario, an angle of 0 means that the line segment between the min index (0) and max index (7) is horizontal on the right half of the circle - the image on the left. In the middle image, the wheel has been rotated 23 degrees. Here the correct answer (x) is 3, as the yellow pointer is on the segment at index 3. In the image on the right, the wheel has been rotated 220 degrees, and the correct answer (x) is 7.

In this wheel, n = 8. There are 8 segments. The angle (a) is how far the wheel has been rotated from its original position.

So given n and a, how would you calculate x?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2025-01-25 12:48:18

只需切换角度并为每个45角范围创建一个箱体:

let angle = 220.0
switch angle.truncatingRemainder(dividingBy: 360) {
case 0..<45: print("3")
case 45..<90: print("2")
case 90..<135: print("1")
case 135..<180: print("0")
case 180..<225: print("7")  // 7
case 225..<270: print("6")
case 270..<315: print("5")
case 315..<360: print("4")
default: break
}

如果您真的想要一个公式,则可以从360中减去角度,将其除以45(截面= 360除以部分数),添加4(初始数量部分偏移),向下和截断提醒除以8(截面数)。

func segment(from angle: Double) -> Double {
    ((360.0-angle) / 45.0 + 4.0).rounded(.down)
        .truncatingRemainder(dividingBy: 8)
}

segment(from: 23)   // 3
segment(from: 60)   // 2
segment(from: 123)  // 1
segment(from: 170)  // 0
segment(from: 220)  // 7
segment(from: 235)  // 6
segment(from: 280)  // 5
segment(from: 322)  // 4

Just switch the angle and create a case for each 45 angle range:

let angle = 220.0
switch angle.truncatingRemainder(dividingBy: 360) {
case 0..<45: print("3")
case 45..<90: print("2")
case 90..<135: print("1")
case 135..<180: print("0")
case 180..<225: print("7")  // 7
case 225..<270: print("6")
case 270..<315: print("5")
case 315..<360: print("4")
default: break
}

if you really want a formula you can subtract the angle from 360, divide it by 45 (section angle = 360 divided by number of sections), add 4 (initial number of sections offset), round down and truncate reminder dividing by 8 (number of sections).

func segment(from angle: Double) -> Double {
    ((360.0-angle) / 45.0 + 4.0).rounded(.down)
        .truncatingRemainder(dividingBy: 8)
}

segment(from: 23)   // 3
segment(from: 60)   // 2
segment(from: 123)  // 1
segment(from: 170)  // 0
segment(from: 220)  // 7
segment(from: 235)  // 6
segment(from: 280)  // 5
segment(from: 322)  // 4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文