答案 0 :(得分:2)
我希望你熟悉polar coordinates。我写了简单的算法来计算角落:
let center = CGPoint(x: 100, y: 100)
let numberOfCorners: Int = 5
let radius = 50.0
var angle:Double = 0.0
let startAngle = M_PI_2
var points: [CGPoint] = []
angle = startAngle
while angle - startAngle < 2*M_PI {
let x = radius * cos(angle) + Double(center.x) // transform polar coordinates to XY
let y = radius * sin(angle) + Double(center.y)
let point = CGPoint(x: x, y: y)
points.append(point)
let angleIncrease = Double(2.0*M_PI)/Double(numberOfCorners)
angle += angleIncrease
}
print(points)
它应该与其他多边形一起使用。您只需指定numberOfCorners和startAngle
(以弧度表示)。我认为iOS
坐标的正确StartAngle是3/2 PI
。
但是对于默认XY plane
来实现图片上的多边形,pi/4
就可以了。