title: Find angle and speed for user touch event around a circle on Android
body: <p>Math has come on my way again and has defeated me. I need your help to regroup and attack again.</p>
  
  <p><strong>What I've got:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/5TLR9.png" alt="enter image description here"></p>
  
  <p>I've got a surfaceview and a circle as a bitmap. I need to rotate the bitmap as the user moves the finger around the circle edge. The faster the user slides, the more I need to rotate the image. Seems simple but not really easy to implement. </p>
  
  <p><strong>What I need</strong></p>
  
  <p>I need to calculate the angle on which to rotate the image on onDraw event. From what I've thought so far I need two things:
  - the angle between new touched point and the old one. I've done a simple function that takes care of this:</p>
  
  <pre><code>     private int getAngleBetweenTwoTouchedPoints(double oldX, double oldY, double newX, double newY)
       {
           return (int) Math.abs(Math.atan2(newY - oldY, newX - oldX));
       }
  </code></pre>
  
  <p>the angle returned by this varies from 0 to 1 and I believe it is correct. By incrementing the image rotation matrix angle by this value I get a slow rotation, basically by 1 unit. So, there is a chance to work, but not ok yet. 
  - so, the second thing I may need is the speed with which the user slides the finger around the screen. So basically something like this:</p>
  
  <p>rotationAngle += angleBetweenTouches+speed</p>
  
  <p>Speed, or velocity as I saw it named is the problem in my case, considering that I don't move only on X or Y but around the circle. I have no idea how to calculate it. I saw VelocityTracker on Android help but I don't know how it could help. </p>
  
  <p>So to recap: I need to be able to rotate the image as the user moves the finger around the image border. Even simpler, when the user stops sliding, the pixel of the image that was below the finger on slide start should be the same when the slide stops. </p>
  
  <p>Any help is greatly appreciated. Thank you</p>