0
我有兩點(觸摸位置),我想知道它們相對於圖像中心之間的角度。兩點之間的簽名角度
Google上搜尋了一段時間後,我發現Law of cosines。
於是我想出了下面的代碼:
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)));
看來工作。但它有一個大問題。角度總是正面的。但我需要能夠識別順時針和逆時針運動。因此,從圖中的點1到點2將是+45,但從2到1將是-45。任何想法如何做到這一點?