2013-04-15 49 views
0

我想提请使用该方法的弧的一部分:.Canvas.drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)绘制的弧是一个圆圈

我对圆,圆心和半径两分。

我需要在椭圆矩形中设置什么以及如何计算startAngle和sweepAngle?

我尝试下面的代码:

m_radiusRect.set(x1, Math.min(y1, y2), x2, Math.max(y1,y2)); 
float startAngle = (float)((Math.toDegrees(Math.atan2(x1 - 360.0, 360.0 - y1)) + 360.0) % 360.0); 
float sweepAngle = (float)((Math.toDegrees(Math.atan2(x2 - 360.0, 360.0 - y2)) + 360.0) % 360.0) - startAngle; 

canvas.drawArc(m_radiusRect, startAngle, sweepAngle, false, m_paint); 

回答

0

this答案,并找到中心点的角度。

基于此,找到x1和x2的两个角度表示a1和a2。

然后,

sweepAngle = a2 - a1; 
startAngle = a1; 

编辑

中给出的链接,因为它看起来不工作不考虑中间的公式。

这里中心(CX,CY)

float startAngle = (int) ((float) Math.toDegrees(Math.atan2(x1 - cx, y1 - cy))); 
     float sweepAngle = (int) ((float) Math.toDegrees(Math.atan2(x2 - cx, y2 - cy))) - startAngle; 

     Rect rect = new Rect(); 

     rect.left = (int) (cx - radius); 
     rect.top = (int) (cy - radius); 
     rect.right = (int) (cx + radius); 
     rect.bottom = (int) (cy + radius); 
+0

它不工作。查看编辑 – piojo

+0

查看最新答案 –

+0

它无法正常工作。我是否需要将useCenter传递给drawArc方法?我尝试在一个示例项目中绘制一个简单的弧线,以查看我在点 – piojo