计算惯性移动设定距离的初始速度
我想将某物移动一段设定的距离。然而,在我的系统中存在惯性/阻力/负加速度。我正在使用这样的简单计算:
v = oldV + ((targetV - oldV) * inertia)
将其应用到多个帧上会使运动“加速”或衰减,例如:
v = 10 + ((0 - 10) * 0.25) = 7.5 // velocity changes from 10 to 7.5 this frame
所以我知道我想要行进的距离和加速度,但不知道初始速度会带我去那里的。也许更好的解释是我想知道如何用力击打台球,使其停在某个点上。
我一直在研究运动方程(http://en.wikipedia.org/wiki/Equations_of_motion< /a>)但无法弄清楚我的问题的正确答案是什么......
有什么想法吗?谢谢 - 我来自设计而非科学背景。
更新:Fiirhok有一个固定加速度值的解决方案; HTML+jQuery 演示:
http://pastebin.com/ekDwCYvj
有没有办法用小数值或缓动函数来做到这一点?根据我的经验,这样做的好处是固定加速度和基于帧的动画有时会超出最终点,需要强制,从而产生轻微的捕捉故障。
I want to move something a set distance. However in my system there is inertia/drag/negative accelaration. I'm using a simple calculation like this for it:
v = oldV + ((targetV - oldV) * inertia)
Applying that over a number of frames makes the movement 'ramp up' or decay, eg:
v = 10 + ((0 - 10) * 0.25) = 7.5 // velocity changes from 10 to 7.5 this frame
So I know the distance I want to travel and the acceleration, but not the initial velocity that will get me there. Maybe a better explanation is I want to know how hard to hit a billiard ball so that it stops on a certain point.
I've been looking at Equations of motion (http://en.wikipedia.org/wiki/Equations_of_motion) but can't work out what the correct one for my problem is...
Any ideas? Thanks - I am from a design not science background.
Update: Fiirhok has a solution with a fixed acceleration value; HTML+jQuery demo:
http://pastebin.com/ekDwCYvj
Is there any way to do this with a fractional value or an easing function? The benefit of that in my experience is that fixed acceleration and frame based animation sometimes overshoots the final point and needs to be forced, creating a slight snapping glitch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
行驶的距离只是速度对时间的积分。您需要将关于时间的表达式与限制 [v, 0] 进行积分,这将为您提供以 v(初始速度)表示的距离表达式。
Distance travelled is just the integral of velocity with respect to time. You need to integrate your expression with respect to time with limits [v, 0] and this will give you an expression for distance in terms of v (initial velocity).
这是一个简单的运动学问题。
在某个时刻 t,物体在恒定加速度下的速度 (v) 描述为:
其中 v0 是初速度,a 是加速度。在您的情况下,最终速度为零(物体停止),因此我们可以求解 t:
为了找到行进的总差,我们对速度(第一个方程)随时间进行积分。我已经很多年没有做过积分了,但我很确定这个结果是:
我们可以用我们之前开发的 t 的方程来代替:
以及 v0 的解:
或者,以一种更编程语言的格式:
在这种情况下,加速度是负值(物体正在减速),我假设它是恒定的,否则这会变得更加复杂。
如果您想在步骤有限的循环中使用它,则需要小心一点。循环的每次迭代代表一段时间。物体的移动量等于平均速度乘以时间长度。迭代时间长度等于 1 的示例循环将如下所示:
This is a simple kinematics problem.
At some time t, the velocity (v) of an object under constant acceleration is described by:
Where v0 is the initial velocity and a is the acceleration. In your case, the final velocity is zero (the object is stopped) so we can solve for t:
To find the total difference traveled, we take the integral of the velocity (the first equation) over time. I haven't done an integral in years, but I'm pretty sure this one works out to:
We can substitute in the equation for t we developed ealier:
And the solve for v0:
Or, in a more programming-language format:
The acceleration in this case is negative (the object is slowing down), and I'm assuming that it's constant, otherwise this gets more complicated.
If you want to use this inside a loop with a finite number of steps, you'll need to be a little careful. Each iteration of the loop represents a period of time. The object will move an amount equal to the average velocity times the length of time. A sample loop with the length of time of an iteration equal to 1 would look something like this:
如果要移动设定距离,请使用以下命令:
If you want to move a set distance, use the following: