c# - Detect if mouse move in circle way -


i try implement mouse movement tracking, when mouse move in circle way or rectangle way show specific message.

bool iswithincircle(int centerx, int centery, int mousex, int mousey, double radius)  {     int diffx = centerx - mousex;     int diffy = centery - mousey;     return  (diffx * diffx + diffy * diffy) <= radius * radius; } 

i detect circle shape using function using mouse location. other way detect mouse movement?
give bit of sample code or link?

you want track mouse movements series of line segments, , use line segments create approximation of circle. if center of circle stays relatively consistent, user moving in circle.

they key 2 consecutive line segments approximate arc of circle. normals center of these line segments (normals perpendicular lines) form lines pass through center of circle. when have 2 or more normals, can calculate center of circle. if center stays relatively consistent user moves mouse around, , angles of normals around center of circle proceeding clockwise or counter-clockwise, have circle.

two consecutive line segments approximating circle

as example:

  1. the user moves 100,0 104,2 106,6, giving 2 lines
  2. the slope of line Δy/Δx. slope of normal -Δx/Δy
  3. the normal of lines 1 starts @ 102,1 , has slope of -1/2 (atan2(-1,2) yields -26°)
  4. the normal of lines 2 starts @ 105,4 , has slope of -2/1 (atan2(-2,1) yields -63°)
  5. these lines intersect @ 99,7
  6. if subsequent line segments give center of 99±t,7±t, t tolerance, have continuous arc
  7. when user has gone consecutively through degrees (or radians) of circle, have made circle

some things consider:

  • since mouse move events typically fire lot, resulting in lots of same value or values right next each other, you'll have wait until have enough movement calculate reasonable normal - you'll have experiment see works you
  • tolerances depend on experimentation shows works you

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -