2 CG点之间的半圈

问题描述 投票:0回答:1

我想在一个圆上的两个点之间绘制一个半圆。主要代表一个时钟,我想画另一条线代表一个小时到另一个小时的进度,因此积分的位置可能会有所不同。首先,我知道我感兴趣的2个点的X和Y。这就是我尝试在UIBezierPath中添加角度的方法。我的问题是,新圈子正确开始,但在完全随机的位置结束

let firstAngle = atan2(redPoint.y - circleCenter.y, redPoint.x - circleCenter.x)

let secondAngle = atan2(bluePoint.y - circleCenter.y, bluePoint.x - circleCenter.x) ```

    let circlePath1 = UIBezierPath(arcCenter: circleCenter,
                                   radius: circleRadius,
                                   startAngle: firstAngle,
                                   endAngle: secondAngle,
                                   clockwise: true) ```

无论我设置了redPoint,圆都从正确的位置开始,但是圆永远不会在bluePoint上。

circle representation and points

ios swift xcode uibezierpath cashapelayer
1个回答
0
投票

您正在反向进行此操作。不要试图从红色和蓝色小圆圈的位置开始确定角度。使用角度放置红色和蓝色的小圆圈。

enter image description here

在那个例子中,我的角度是-1和2.8(弧度)。首先,我画出弧线(就像你一样);然后叠加圆圈,这很简单,因为通过将极坐标转换为笛卡尔坐标,我知道它们的中心在哪里(弧的端点)。

© www.soinside.com 2019 - 2024. All rights reserved.