9

enter image description here

I'm really stuck on how to go about programming this. How to draw a circle in Android Canvas with a radius and points around the edge?

What is best approach to design this?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
user991429
  • 322
  • 1
  • 5
  • 15
  • possible duplicate of http://stackoverflow.com/questions/18073084/draw-circle-and-points-on-circle-edge – Raghunandan Aug 06 '13 at 11:40
  • 1
    possible duplicate of [Draw a circle with a radius and points around the edge](http://stackoverflow.com/questions/2508704/draw-a-circle-with-a-radius-and-points-around-the-edge) – g00dy Aug 06 '13 at 11:45
  • Please some one help me for same. Help will be appreciated ... – user991429 Aug 06 '13 at 19:52
  • I want to use this circular image but main thing want to place multiple pins on circle edge. – user991429 Aug 07 '13 at 08:21

2 Answers2

7

the point(cX,cY) you want draw

the center point(centerX,centerY) of the circle

the radius of the circle

the angle is the point(cX,cY) on the circle.

also see the image:

https://i.stack.imgur.com/2Dx2r.jpg

the code:

cX = centerX + radius*Math.cos(angle*Math.PI/180);
cY = centerY + radius*Math.sin(angle*Math.PI/180);
canvas.drawCircle(cX, cY, radius, paint); 
Sea
  • 71
  • 1
  • 3
3

Well; drawing a circle is a very straightforward, inside your onDraw() method add this line

canvas.drawCircle(cX, cY, radius, paint); 

Simply provide the center point's x and y values and radius and paint object as well.

And for the pins around the corner you can go like this, e.g you want a pin at 30 degrees; with a simple trigonometric calculation, your pin's x and y values can be these;

pX = mX + radius * Math.cos(Math.toRadians(30));
pY = mY + radius * Math.sin(Math.toRadians(30));

So you can draw your pin at these x and y values respectively, also the degree can be changed.

Nexen
  • 1,663
  • 4
  • 16
  • 44
Onur A.
  • 3,007
  • 3
  • 22
  • 37