Aam*_*irR 3 geometry ios swift
我得到了一个中心CGPoint和半径Float,我需要在圆圈周围得到N个点,例如在下面的图像中如何得到12个点对应的红点.
这是我不完整的功能:
func getCirclePoints(centerPoint point: CGPoint, and radius: CGFloat, n: Int) [CGPoint] {
let result: [CGPoint] = stride(from: 0.0, to: 360.0, by: CGFloat(360 / n)).map {
let bearing = $0 * .pi / 180
// NO IDEA WHERE TO MOVE FURTHER
}
return result
}
getCirclePoints(centerPoint: CGPoint(x: 160, y: 240), radius: 120.0, n: 12)
Run Code Online (Sandbox Code Playgroud)
你快到了!
func getCirclePoints(centerPoint point: CGPoint, radius: CGFloat, n: Int)->[CGPoint] {
let result: [CGPoint] = stride(from: 0.0, to: 360.0, by: Double(360 / n)).map {
let bearing = CGFloat($0) * .pi / 180
let x = point.x + radius * cos(bearing)
let y = point.y + radius * sin(bearing)
return CGPoint(x: x, y: y)
}
return result
}
let points = getCirclePoints(centerPoint: CGPoint(x: 160, y: 240), radius: 120.0, n: 12)
Run Code Online (Sandbox Code Playgroud)
我不认为and作为一个参数名称非常清楚所以我删除了这个.
| 归档时间: |
|
| 查看次数: |
542 次 |
| 最近记录: |