Detecting specific mouse movements

What would be the best way to detect specific mouse movements using the MouseMotionListener? For example, detecting if the user moved their mouse in a circle.

Interesting question…

You could try fitting the user’s mouse points to a pattern. You’d do something like this for a circle

  • Collect X number of mouse points (could be based on time or just the last x mouse movements, either way you have a collection of them)
  • Find the points with the smallest x and y
  • Find the points with the largest x and y
  • Take the four points and use the largest and smallest values to construct two new points, which define a bounding box that encompasses all points
  • Calc the center of the box
  • Create a circle shape, centered in the bounding box with a radius of half the length of the bounding box (you now have a large circle inscribed in a box)
  • Create a smaller circle, centered, that extends to say 1/4 the length of the box.
  • Now count the number of points that exist between the two circles

You’d have to decide an appropriate number and a tolerance on the relative circle size. This assumes you’re trying to detect not only a circle, but roughly a certain size of circle as well.

Pictures might make more sense in describing this back of the napkin type idea.

Regards,
Dr. A>