Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...