问题描述
在我的应用中,我正在使用UIBezierPath将圆弧绘制成一个圆.我正在尝试将数字与弧度相关联.因此,假设用户有一定数量的点,并且这些点的上限为100点.我希望100点为360度.我希望圆的前33%为绿色,然后从圆的34%至下一个66%用橙色描边,然后从67%到100%用红色描边.
In my app I'm using UIBezierPath to draw an arc into a circle. I'm trying to correlate a number to radians. So let's say a user has a certain number of points, and the points are capped at 100 points. I want 100 points to be 360 degrees. I want the first 33% of the circle to be green, and then from 34% to the next 66% of the circle to be stroked in orange, and then from 67% to 100% in red.
我在这里遇到的问题是将圆的百分比转换为弧度.创建UIBezier路径时,我需要提供一个startAngle和endAngle,将这些点转换为弧度值时会遇到一些麻烦.
The issue I'm having here is converting percents of a circle to radians. When creating a UIBezier path, I need to provide a startAngle and endAngle, and I'm having a bit of trouble converting these points to radian values.
我将如何解决这个问题?
How would I go about solving this?
谢谢
推荐答案
Objective-C
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
这篇关于如何在Objective-C中将点转换为弧度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!