ios - 如何在 UIBezierPath 弧中获取半径的中心点?

标签 ios objective-c uibezierpath cashapelayer cgpoint

我有 objective c 应用程序。在 ViewController 中,我有一个 UIView,在这个 View 中,我使用以下代码用 UIBezierPath 绘制了一个圆圈:

CAShapeLayer* clockWiseLayer = [[CAShapeLayer alloc] init];
        clockWiseLayer.path = [UIBezierPath bezierPathWithArcCenter:centerPoint
                                                              radius:radius
                                                          startAngle:startAngle
                                                            endAngle:endAngle
                                                           clockwise:YES].CGPath;

然后我想知道什么是点到部分的中心或半径中心到零件圆弧中心的位置,如下所示:

enter image description here

我怎样才能得到这个点?如果我知道角度的终点、起点、半径大小,该点的值是多少,我该如何计算?

最佳答案

所有这些只是一些基本的三角函数。

首先得到圆弧中心的角度:

normalEnd = endAngle < startAngle ? endAngle + 2 * pi : endAngle
centerAngle = startAngle + (normalEnd - startAngle) / 2

然后计算圆弧圆心相对圆心点的x、y坐标:

arcCenterX = centerPoint.x + cos(centerAngle) * radius
arcCenterY = centerPoint.y + sin(centerAngle) * radius

现在你有了线段的端点,你想要线段的中心:

desiredPointX = (centerPoint.x + arcCenterX) / 2
desiredPointY = (centerPoint.y + arcCenterY) / 2

关于ios - 如何在 UIBezierPath 弧中获取半径的中心点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48918788/

相关文章:

iphone - iOS Overlay View 总是位于顶部?

iOS 11 AVPlayerViewController 禁用捏合/拖动手势

ios - 对象在初始化后立即释放

ios - 在 UITableView 中滚动的自定义 View

ios - 立陶宛语名词翻译结合 iOS 中的数字

html - 在iOS中使UIWebview的字体加粗

objective-c - 如何在cocoa(Interface Builder)中绑定(bind)CGSize.width?

ios - 单边角的反向 UIBezierPath

algorithm - 如何阻止贝塞尔样条曲线超出坐标轴?

ios - 如何绘制 UIBezierPath 并与之交互