作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当描边和填充可配置时,如何使用贝塞尔曲线路径绘制闭合的新月?所以汽车我可以得到一条曲线,但还没有找到连接和绘制另一条曲线的策略。
最佳答案
如果你想要更好地近似于天文正确的新月(外弧为 180 度),我可能会建议如下:
CGFloat angle = M_PI_2 * 0.60; // how much of a crescent do you want (must be less than M_PI_2 and greater than zero)
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:TRUE];
[path addArcWithCenter:CGPointMake(center.x - radius * tan(angle), center.y) radius:radius / cosf(angle) startAngle:M_PI_2 - angle endAngle:angle - M_PI_2 clockwise:FALSE];
[path closePath];
产生:
如您所见,路径基本上由两条圆弧定义,一条顺时针,一条逆时针。内弧的中心、半径以及起点和终点角度的细节是基本三角学的问题(但实际公式将根据所需的精确外观和感觉而有所不同)。例如,在我的代码片段中,我上面代码中的 angle
是下图中的蓝色角度,然后我计算红色三角形将用于确定正确的起点和终点角度以及中心对于内弧。
下面有人问逆时针旋转 90 度,比如:
在 Swift 中,这将是:
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: -.pi, endAngle: 0, clockwise: true)
path.addArc(withCenter: CGPoint(x: center.x, y: center.y + radius * tan(angle)), radius: radius / cos(angle), startAngle: -angle, endAngle: -.pi + angle, clockwise: false)
path.close()
关于ios - 如何在 iOS 中使用贝塞尔曲线路径创建新月?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30084585/
我是一名优秀的程序员,十分优秀!