2012-09-05 34 views
1

在我的自定義視圖,我繪製多個充滿Arc就像這樣:在Arc中心繪製位圖?

canvas.drawArc(oval, startAngle, sweepAngle, true, sectorPaint); 

現在,我想在圓弧的圓心繪製圖標。我開始與此:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_icon); 
canvas.drawBitmap(bitmap, pointX, pointY, null); //pointX & pointY ?? 

不過,我不知道我應該爲pointXpointY設置。這裏是我擁有的數據:

  • 橢圓圓心座標和半徑。
  • 由startAngle和sweepAngle(因此,endAngle可以得出)

有沒有辦法知道價值pointXpointY給那些投入?


編輯:插圖草圖:

enter image description here

+0

你可以把屏幕截圖也想實現 –

+0

@SunnyKumarAditya編輯與草圖什麼。請看看。 – iTurki

回答

2

This answer幫了我很多經過一番調整:

double radius = width/2; 
double x = radius + (radius)*Math.cos(-angle); 
double y = radius + (radius)*Math.sin(-angle); 
+0

我認爲這隻適用於起始角度爲0的情況。有沒有方法可以設置非零的起始角度和結束角度,並仍然獲得其中心? –

0

使用您的增值經銷商。

試試這個:

double x = C.x + r * Math.cos(theta * Math.PI/180); 
double y = C.y + r * Math.sin(theta * Math.PI/180); 

其中thetaarc結束角 - start angle of arc