image

I have circle in Android, and I want to calculate the angle between the circle center and two points:
The first point is the up center in the circle like 12 on a clock, and the second is the event point.

how can I do this?

public boolean onDrag(View v, DragEvent event) {
float radius = v.getWidth()/2;
float center_circleX =  v.getX()+radius;
float center_circleY =  v.getY()+radius;
float x = event.getX();
float y = event.getY();
float x1 = radius;
float y1 = radius
//int angleDegrees = ? from 0 to 360
}

1 Answers

0
SiMo On

try something like this :

float angle = Math.toDegrees(
  Math.atan2(y1 - center_circleY, x1 - center_circleX) -
  Math.atan2(y - center_circleY, x - center_circleX)
);