【问题标题】:Calculate x/y Coordinates from Angle for every Point从角度计算每个点的 x/y 坐标
【发布时间】:2017-04-23 09:50:26
【问题描述】:

我想订购 28 件商品。 我有一个给定的角度和半径,我需要计算我的坐标。 有人可以帮帮我吗?

【问题讨论】:

  • 不清楚,你到底想要什么。你不能添加说明吗?你在说什么?
  • 我想订购 28 个 Button in a Circle。我想计算我的坐标以获得一个完美的圆,但我不知道如何做到这一点。按钮应该像时钟一样排列。
  • Polar coordinate system;尤其参见极坐标和笛卡尔坐标之间的转换部分。在您的情况下,每个按钮之间的角度增量为2π/28(弧度)。
  • 你想创建 28 个按钮,它们会在圆圈中吗?

标签: math coordinates


【解决方案1】:

这是一道简单的数学题,不是 Swift 题。

let circle = 2.0 * Double.pi
for angle in stride(from: 0.0, to: circle, by: circle / 28.0) {
    let x = radius * cos(angle)        
    let y = radius * sin(angle)
    // Add x & y to the coordinates of your centre.
}

【讨论】:

  • 对于大型数据集,可能只计算第一象限,并使用圆的对称性来推断其余部分。 Sin 和 cos 在大多数拱门上都有相当高的延迟
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-07
相关资源
最近更新 更多