Any idea how to track the mouse moving speed?

S

Sowen Zhang

Hi,

Suppose a user presses the mouse on an object, then drags the object around.
When the user releases the mouse, I want to tell what's the average speed of
the whole movement. Any idea how to calculate that?

Because the user can drag the object to any direction, it could go right,
then go left, then go up, go right, go left, ect. And the speed of each
section varies, I can't use the starting point and ending point as the
distance then divide by the time comsuned.

What I am doing is, in each MouseMove event, I store the point (section). I
calculate the average speed for every two sections as follows:

d1 = p2-p1;
v1 = d1 / 2; // 2 means 2 frames
d2 = p3-p2;
v2 = d2 / 2;

v = 2 / (1/v1 + 1/v2); // mean

Assume every MouseMove happens evenly. In fact, I am not going to track
mouse but finger. In that case, there is no FingerMove event, but only a
camera frame update event, every frame is updated constantly.

Now I am using a harmonic mean to compute the average speed for every two
sections, but the result doesn't look right.

I hope it makes sense, any help will be appreciated.


--
Best Regards!
Hong.
---------------------------
Image Processing and Watermark components for .NET
http://www.ImageComponent.NET

Personal Entertainment Shareware and Freeware
http://www.angGoGo.com
 
K

Kevin Spencer

Speed = distance / time.

Therefore, you need to know the time difference to calculate the speed. This
means that every time you sample a distance, you must know the time interval
of the sample. I hope your assumption is correct!

As for your math, you can average 2 values by dividing by 2, only if the 2
values represent the same thing. So, if 2 values represent the same time
interval, the average is accurate. But if one value represents a cumulative
time interval, and the other represents a single time interval, the average
is inaccurate. Each time you average 2 values, the result represents a
cumulative time interval. The average of 10 distances over 10 ms has more
weight than the value of 1 distance for 1 ms, by a factor of 10.


--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top