Calculating the Angle of a Swipe Gesture
Posted: Sun Oct 12, 2014 6:31 pm
I'm partly sharing, and partly looking for any suggestions to see if anyone thinks there is a better method...
The following script calculates the angle of a swipe gesture by comparing the start and end points.
0 degrees is straight right
90 degrees is straight down
180 degrees is straight left
270 degrees is straight up
The following script calculates the angle of a swipe gesture by comparing the start and end points.
0 degrees is straight right
90 degrees is straight down
180 degrees is straight left
270 degrees is straight up
Code: Select all
global gCoor
on touchStart pID
put empty into gCoor["xstart"]
put empty into gCoor["xend"]
put empty into gCoor["ystart"]
put empty into gCoor["yend"]
put empty into gCoor["swipeangle"]
end touchStart
on touchMove pID, px, py
if gCoor["xstart"] is empty then
put px into gCoor["xstart"]
put py into gCoor["ystart"]
else
put px into gCoor["xend"]
put py into gCoor["yend"]
end if
end touchMove
on touchEnd
put gCoor["yend"] - gCoor["ystart"] into tyDiff
put gCoor["xend"] - gCoor["xstart"] into txDiff
if atan2(tyDiff,txDiff) < 0 then
put atan2(tyDiff,txDiff) *(180/pi)+360 into gCoor["swipeangle"]
else
put atan2(tyDiff,txDiff) *(180/pi) into gCoor["swipeangle"]
end if
end touchEnd