我的屏幕上有3分:
a = a point which is (c.x, 0) makes a line pointing straight up
b = a user input touch, can be anywhere on the screen
c = a moving object
a
_______.________
| | |
| | |
| b | |
| . | |
| \ | |
| \ | |
| \| |
| | c |
|______._______|
我画了一些线,以便您可以看到向量。
我希望能够获得a和b之间的角度。我已经尝试过了,但是没有用,有人知道我在做什么错吗?:
//v1 moving object
float boxX = this.mScene.getLastChild().getX();
float boxY = this.mScene.getLastChild().getY();
//v2 user touch
float touchX = pSceneTouchEvent.getX();
float touchY = pSceneTouchEvent.getY();
//v3 top of screen
float topX = boxX;
final float topY = 0;
float dotProd = (touchX * topX) + (touchY * topY);
float sqrtBox = (touchX * touchX) + (touchY * touchY);
float sqrtTouch = (topX * topX) + (topY * topY);
double totalSqrt = sqrtBox * sqrtTouch;
double theta = Math.acos(dotProd / Math.sqrt(totalSqrt));
我通常得到的答案是0到1。如何解决这个问题,以便获得角度(以度为单位)?