iturki iturki - 3 months ago 29
Android Question

Draw a Bitmap in Arc center?

In my Custom View, I draw multiple filled

Arc
s like this:

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


Now, I want to draw an icon on the center of the Arc. I started with this:

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


However, I don't know what should I set for
pointX
and
pointY
. Here is the data I have:


  • Oval center coordinates and radius.

  • startAngle and sweepAngle (and therefore, endAngle can be derived)



Is there a way to know the values
pointX
and
pointY
giving those inputs?




Edit: an illustration sketch:

enter image description here

Answer

This answer helped me a lot after some adjustments:

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