答案 0 :(得分:3)
这是工作代码。
func findEquidistantPoints(startPoint: CGPoint, endPoint: CGPoint, pointsCount: UInt) -> [CGPoint] {
let count = CGFloat(pointsCount + 1)
let xDelta = (endPoint.x - startPoint.x) / count
let yDelta = (endPoint.y - startPoint.y) / count
return Array(1...pointsCount).map { CGPoint(x: startPoint.x + CGFloat($0) * xDelta, y: startPoint.y + CGFloat($0) * yDelta) }
}
findEquidistantPoints(CGPoint(x: 10, y: 23), endPoint: CGPoint(x: 34, y: 45), pointsCount: 3)