Reputation: 807
I am working on an iOS/iPad educational app that will display a clock with 2 hands (hour and minute). When the user spins there finger on the clock face I want to move the time either forward or backward. This will be a single finger gesture or spinning motion.
Any ideas on how to tell if the user is spinning their finger clockwise or counter clockwise around the circular clock face?
I thought about calculating the angle, then translating the angle into a "section" of say 30 degrees. Then watching the pattern of sections that are tripping.
Just wondering if anyone has a "whiz bang" solution that I am not considering? Something elegant perhaps?
Thanks.
Upvotes: 2
Views: 671
Reputation: 3991
What you need to do is keep at least three points, then just calculate the area of the "triangle" they form.
CGPoint a = lastStart;
CGPoint b = start;
CGPoint c = end;
float area = a.x * b.y - a.y * b.x + a.y * c.x - a.x * c.y + b.x * c.y - c.x * b.y;
if(area > 0) {
// you're moving CCW
}
Upvotes: 1
Reputation: 5421
Make starting point of the gesture nominal 0,0 and divide the screen into four quadrants with x and y axes running through your nominal 0,0. Note which quadrants get visited, in turn. After the first two, you have the directionality:
Movement into lower right quadrant followed by movement into upper right is counterclockwise
Movement into lower right quadrant followed by movement into lower left is clockwise
Movement into lower left quadrant followed by movement into lower right is counterclockwise
Movement into lower left quadrant followed by movement into upper left is clockwise
Movement into upper left quadrant followed by movement into lower left is counterclockwise
Movement into upper left quadrant followed by movement into upper right is clockwise
etc etc
Upvotes: 0