方法一(余弦定理):
private double getRotate(double x1, double y1, double x2, double y2) {
double abx = centerX - x1;
double aby = centerY - y1;
double acx = centerX - x2;
double acy = centerY - y2;
double bcx = x2 - x1;
double bcy = y2 - y1;
double c = Math.hypot(abx,aby);
Log.e("TAG","c == " + c);
double b = Math.hypot(acx,acy);
Log.e("TAG","b == " + b);
double a = Math.hypot(bcx,bcy);
Log.e("TAG","a == " + a);
double cos1 = (c*c + b*b - a*a)/(2*b*c);
Log.e("TAG","cos == " + cos1);
if (cos1 >= 1) {
cos1 = 1f;
}
double radian = Math.acos(cos1);
double degree = Math.toDegrees(radian);
}
方法二:
private double getRotate(double x1, double y1, double x2, double y2) {
double v1 = (abx * acx) + (aby * acy);
double abx = centerX - x1;
double aby = centerY - y1;
double acx = centerX - x2;
double acy = centerY - y2;
double bcx = x2 - x1;
double bcy = y2 - y1;
double abL = Math.sqrt(abx*abx + aby*aby);
double acL = Math.sqrt(acx*acx + acy*acy);
double cos = v1 / (abL*acL);
Log.e("TAG","cos1 == " + cos);
double radian = Math.acos(cos);
double degree = Math.toDegrees(radian);
return degree;
}
3 鸿洋的圆形菜单的方法
/**
* 算出该点与水平的角度的值,用移动点角度减去起始点角度就是旋转角度。
*/
private double getAngle(double xTouch, double yTouch) {
double x = xTouch - centerX;
double y = yTouch - centerY;
return (double) (Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI);
}
1