gpt4 book ai didi

ios - 如何在 iOS 中使用贝塞尔曲线路径创建新月?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:02 26 4
gpt4 key购买 nike

当描边和填充可配置时,如何使用贝塞尔曲线路径绘制闭合的新月?所以汽车我可以得到一条曲线,但还没有找到连接和绘制另一条曲线的策略。

enter image description here

最佳答案

如果你想要更好地近似于天文正确的新月(外弧为 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];

产生:

result

如您所见,路径基本上由两条圆弧定义,一条顺时针,一条逆时针。内弧的中心、半径以及起点和终点角度的细节是基本三角学的问题(但实际公式将根据所需的精确外观和感觉而有所不同)。例如,在我的代码片段中,我上面代码中的 angle 是下图中的蓝色角度,然后我计算红色三角形将用于确定正确的起点和终点角度以及中心对于内弧。

howto


下面有人问逆时针旋转 90 度,比如:

enter image description here

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com