[英]How to convert points to radians in Objective-C?
在我的應用程序中,我使用 UIBezierPath 將圓弧繪制成圓。 我試圖將一個數字與弧度相關聯。 所以假設用戶有一定數量的積分,積分上限為 100 分。 我希望 100 點是 360 度。 我希望圓圈的前 33% 是綠色,然后從圓圈的 34% 到接下來的 66% 用橙色描邊,然后從 67% 到 100% 用紅色描邊。
我在這里遇到的問題是將圓的百分比轉換為弧度。 創建 UIBezier 路徑時,我需要提供 startAngle 和 endAngle,並且在將這些點轉換為弧度值時遇到了一些麻煩。
我將如何解決這個問題?
謝謝
CGFloat radians = percent * 0.01 * 2 * M_PI;
簡單代數。
使其更通用,您可以編寫一個轉換函數:
func radiansFromPercent(_ percent: CGFloat) -> CGFloat {
return percent * 0.01 * 2 * CGFloat.pi
}
目標-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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.