I have 3 points on my screen:
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 | |______._______|
I have drawn some lines so that you can see the vectors.
I want to be able to get the angle between a and b. I have tried this, but it doesn't work, does anyone know what I'm doing wrong?:
//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));
The answer I usually get is between 0 and 1. How do I fix this so that I get the angle in degrees?