我想在圆上垂直画一条线(截取圆弧),如图所示。
我正在使用这段代码画圆
let center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: Conversion.degreesToRadians(value: CGFloat(0)), endAngle: Conversion.degreesToRadians(value: CGFloat(360)), clockwise: true)
path.lineWidth = 2
path.lineCapStyle = CGLineCap.square
UIColor.white.setStroke()
path.stroke()
最佳答案
基本思想是圆以CGPoint
为中心有一定的半径。要找出圆上的一个点,您可以像这样计算 x 和 y 坐标:
func point(center: CGPoint, radius: CGFloat, angle: CGFloat) -> CGPoint {
let x = center.x + radius * cos(angle)
let y = center.y + radius * sin(angle)
return CGPoint(x: x, y: y)
}
角度以弧度为单位,从 3 点钟方向开始,顺时针方向。
所以那些垂直相交的笔划只是两个 CGPoint
之间给定角度的线段,例如,线段起点的“半径”可能小于圆的半径。对于直线的终点,使用相同的角度,但使用的半径值刚好大于圆的半径。
关于ios - 如何绘制与弧垂直相交的线(核心图形)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45158467/