I have two points (touch positions) and I want to know angle between them relative to image center.
After googling for a while, I found Law of cosines.
So I came up with the following code:
final float x = e.getX() - v.getWidth() / 2;
final float y = e.getY() - v.getHeight() / 2;
final float a = PointF.length(x, y);
final float b = PointF.length(x_, y_);
final double c = Math.sqrt(Math.pow(x - x_, 2) + Math.pow(y - y_, 2));
final double alpha = Math.toDegrees(Math.acos((Math.pow(a , 2) + Math.pow(b, 2) - Math.pow(c, 2)) / (2 * a * b)));
It seems to work. But it has one big issue. The angle is always positive. But I need to be able to recognize clockwise and counterclockwise movement. So from point 1 to point 2 in illustration would be +45 but from 2 to 1 would be -45. Any idea how to do that?