如何在Objective-C中将点转换为弧度?

在我的应用程序中,我使用UIBezierPath将圆弧绘制成一个圆。 我正在试图将一个数字与弧度关联起来。 因此,假设用户有一定数量的积分,积分上限为100分。 我想要100分是360度。 我想要第一个33%的圆圈是绿色的,然后从34%到下一个66%的圆圈要橙色,然后从67%到100%的红色。

我在这里遇到的问题是将圆的百分数转换为弧度。 当创build一个UIBezierpath时,我需要提供一个startAngle和endAngle,并且在将这些点转换为弧度值时遇到了一些麻烦。

我将如何去解决这个问题?

谢谢

CGFloat radians = percent * 0.01 * 2 * M_PI; 

简单的代数。

我想你想要的是单位圈子。 当你使用单位圆时,记得回到三angular? 这里同样适用。 如果你需要在Swift中获得π – 只要let π = CGFloat.pi (保持alt + p为特殊字符)。 在Objective-C中,我认为它是CGFloat π = M_PI;

在这里输入图像说明

你可以从零到2π/3为前1/3,然后从2π/34π/3 ,然后从4π/3 (全圆)。

我不应该说我没有制作这个graphics – 它来自RayWenderlich.com上的一个教程 – 但是它完全针对iOS坐标系。

Objective-C的

 CGFloat fullCircle = 2 * M_PI ; // M_PI Pi number which is half of the circle in radian CGFloat startPoint = 0.0 ; CGFloat endPoint = fullCircle * 0.33 ; // Assuming circling clockwise // .... Draw first step UIBezierPath startPoint = endPoint ; endPoint = startPoint + fullCircle * 0.33 ; // .... Draw second step UIBezierPath startPoint = endPoint ; endPoint = fullCircle - startPoint ; // This to make sure the whole circle will be covered // .... Draw the last step UIBezierPath 

迅速

 let fullCircle = 2 * M_PI // M_PI Pi number which is half of the circle in radian var startPoint: Float = 0.0 var endPoint: Float = fullCircle * 0.33 // Assuming circling clockwise // .... Draw first step UIBezierPath startPoint = endPoint endPoint = startPoint + fullCircle * 0.33 // .... Draw second step UIBezierPath startPoint = endPoint endPoint = fullCircle - startPoint // This to make sure the whole circle will be covered // .... Draw the last step UIBezierPath 
Interesting Posts