【问题标题】:How to get center point of radius in UIBezierPath arc?如何在 UIBezierPath 弧中获得半径的中心点?
【发布时间】:2018-02-22 02:40:08
【问题描述】:

我有目标 c 应用程序。在 ViewController 中我有一个 UIView,在这个视图中我用 UIBezierPath 画了一个圆圈,代码如下:

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

然后我想知道点到部分的中心或半径到部分圆弧中心的中心是这样的:

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

【问题讨论】:

    标签: ios objective-c uibezierpath cashapelayer cgpoint


    【解决方案1】:

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

    先得到圆弧中心的角度:

    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
    

    【讨论】:

    • 如果我没有弄错@user3386109,如果您申请+,那么您将获得圆的上限,如果您申请-,那么您将获得最低点。这两种情况你肯定会得到中心点。看到这张图片google.co.in/…:
    • @user3386109 这是错误的。我刚刚做了一个更新,现在应该是正确的。
    • @rmaddy LOL 忘记分了
    • @user3386109 好的,我想我终于明白了。我需要标准化结束角度,使其大于开始角度。查看更新。
    猜你喜欢
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 2021-04-09
    • 2020-09-24
    • 2014-05-12
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多