I would like to simulate an analog joystick on the touchable screen like this picture.
When the center of the stick area is set to (cx, cy), how should I calculate X-direction ratio and Y-direction ratio(-1.0~1.0) from the touched position(tx, ty)?

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The x direction ratio is (tx-cx)/r, where r is the radius magnitude of the circle. Similarly, the y direction ratio is (ty-cy)/r.
I am assuming a right-handed cartesian coordinate with x axis in the direction of the right of the picture. Otherwise, you may need to multiply a (-1) to adjust the direction.