我正在使用UIBezierPath绘制弧线。我怎样才能计算出这个弧的中点。
let center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
var startValue: CGFloat = 0
var startAngle: CGFloat = 0
var endValue: CGFloat = 0
var endAngle: CGFloat = 0
startAngle = (startValue * 2 * CGFloat(M_PI)) - CGFloat(M_PI_2)
endValue = startValue + 0.20
endAngle = (endValue * 2 * CGFloat(M_PI)) -CGFloat(M_PI_2)
let path = UIBezierPath()
path.moveToPoint(center)
path.addArcWithCenter(center, radius: radius.outer, startAngle: startAngle, endAngle: endAngle, clockwise: true)
path.fill()
path.stroke()
答案 0 :(得分:5)
midPoint角度将是startAngle
和endAngle
的平均值。这会根据center
点和radius.outer
:
let midPointAngle = (startAngle + endAngle) / 2.0
let midPoint = CGPoint(x: center.x + radius.outer * cos(midPointAngle), y: center.y - radius.outer * sin(midPointAngle))