Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

winforms - Find the velocity of the mouse in C#

How can i find the instantaneous vertical speed of the mouse at the exact moment that the mouse is released? i have the users dragging over a custom control and when they release i need to know this information so i can continue the object they were dragging using the vertical component of the velocity...

so for instance, if they were dragging at an angle, use trig to determine the vertical speed and then use that..

i cant just do distance over time, because the mouse can be moved at irregular speeds and this will not represent the correct velocity at all.

I was thinking that there might be a specific interval between the triggers of MouseMove that i could use, but im not sure.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How can i find the instantaneous vertical speed of the mouse at the exact moment that the mouse is released?

You can't. As Zeno made clear centuries ago, speed is only meaningful over a period of time. If I had to do it, I'd probably use a weighted moving average, so (for example) I computed the distance/time for each of the last 5 mouse movement messages, but their importance "decayed" over time. For example, I might multiply the most recent by 1, the next one back by .8, the next one back by .6, and so on. This way if (for example) they happen to slow down (or speed up) the movement just as they release the button, you still get a reasonable approximation of what they were doing just prior to that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...