iturki iturki - 1 year ago 159
Android Question

Draw a Bitmap in Arc center?

In my Custom View, I draw multiple filled

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
. 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
giving those inputs?

Edit: an illustration sketch:

enter image description here

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download