I am trying to calculate the direction of a swipe on a touch device screen. Lets say the screen size is 1024 wide and 768 high. The bottom left x and y coordinate is 0,0 and the top right coordinate is 1024,768.
For any given swipe, I will receive a delta vector which indicates the movement on the x and y axis. For instance, if I start a touch at 100,100 and the end the touch at 500,150 I will receive a delta vector of 400,50 and I know from this that the swipe was to the right (and a tiny bit up).
From any given delta vector, is there a formula I can use to determine which direction the vector most resembles, allowing for diagonal swiping too (i.e. left, right, up, down, up-left, up-right, down-left, down-right). I do have some code which calculates the closest with an allowed margin for error - but it occurred to me there must be a mathematical way to solve this without having to check each direction and the margin.
Hope that makes sense, Thank you.
P.s. Already tried to post this in the math overflow site, but got shot down as apparently it's not a math problem. Which actually it is. Hope this is a better choice!
EDIT:
Bornander: The solution you gave (which is very clever) provides the detection as shown in this image...
Where what I'm realistically after is a slightly turned version like this...