Search code examples
algorithmmathrotationmulti-touchgestures

How to calculate (approximate) rotation of a list of (x, y) points


I am detecting multitouch gestures in a XNA app, such that certain "panels" on the screen can accept touch points within their bounds, and then move, scale or rotate according to user fingers' movement.

However, since the screen is a large multitouch screen with 10s of touch points, a panel can sometimes accept 5 (or even more) fingers at the same time, and most of the stuff I found online is limited to gestures using 2 touch points only.

I have handled move and scale gestures by calculating a center point for all touches on a certain panel:

  1. Calculate center point for current touches (avg x, avg y)
  2. Calculate center point for previous timestamp touches (avg x, avg y)
  3. Use the difference to move and scale the panel.

But I have no clue how to approach rotation. Is there an algorithm to quickly get this (approximate) rotation angle? Should I calculate the angle between each point and the center, and then use the delta value? Is there perhaps a better approach?


Solution

  • How about you find the two points with the largest distance and use those. That makes the most intuitive sense to me.

    Imagine rotating with one hand spread and all 5 fingers on the screen, all that matters in this case is getting rotation between thumb and pinkie.

    Or consider a two handed gesture with two fingers from each hand. Again, with this method you would ignore rotations within a single hand, but capture the wide sweep of each hand.

    The only way that this breaks is doing a rotation with two fingers of one hand, and another hand is sitting idle on the screen somewhere. Then the rotation will appear to not work ( e.g. that second hand is pivoting, but you are looking for angle from hand to hand. )