Glam Prestige Journal

Bright entertainment trends with youth appeal.

$\begingroup$

If I have the coordinates of two points, how would I determine what direction the second point lies in, relative to the first point? Specifically, I'm writing an application that involves basically drawing an arrow starting at a certain area on the screen, pointing in the direction of the mouse.

$\endgroup$ 1

1 Answer

$\begingroup$

From $(x_1, y_1)$ to $(x_2, y_2)$ the direction is $\text{atan2}(y_2 - y_1, x_2 - x_1)$

You wrote you were writing a program, so atan2 is the easiest solution, it's usually found in your languages math package. In java it's Math.atan2(y, x)

$\endgroup$ 4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy