use*_*888 0 objective-c cashapelayer cgpoint ios uibezierpath
我有 Objective C 应用程序。在 ViewController 中,我有一个 UIView,在这个视图中,我用 UIBezierPath 画了一个圆圈,代码如下:
CAShapeLayer* clockWiseLayer = [[CAShapeLayer alloc] init];
clockWiseLayer.path = [UIBezierPath bezierPathWithArcCenter:centerPoint
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:YES].CGPath;
Run Code Online (Sandbox Code Playgroud)
然后我想知道部分的点中心或部分圆弧中心的半径中心是什么,如下所示:
我怎样才能得到这一点?如果我知道角度的终点、起点、半径大小,该点的值是多少?如何计算?
所有这些只是一些基本的三角学。
首先得到圆弧中心的角度:
normalEnd = endAngle < startAngle ? endAngle + 2 * pi : endAngle
centerAngle = startAngle + (normalEnd - startAngle) / 2
Run Code Online (Sandbox Code Playgroud)
然后计算圆弧中心相对于中心点的x和y坐标:
arcCenterX = centerPoint.x + cos(centerAngle) * radius
arcCenterY = centerPoint.y + sin(centerAngle) * radius
Run Code Online (Sandbox Code Playgroud)
现在您有了线段的端点,并且需要该线段的中心:
desiredPointX = (centerPoint.x + arcCenterX) / 2
desiredPointY = (centerPoint.y + arcCenterY) / 2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2004 次 |
| 最近记录: |