计算惯性移动设定距离的初始速度

发布于 2024-08-25 13:47:51 字数 790 浏览 3 评论 0原文

我想将某物移动一段设定的距离。然而,在我的系统中存在惯性/阻力/负加速度。我正在使用这样的简单计算:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海里的那抹蓝 2024-09-01 13:47:52

行驶的距离只是速度对时间的积分。您需要将关于时间的表达式与限制 [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).

眼眸里的那抹悲凉 2024-09-01 13:47:51

这是一个简单的运动学问题。

在某个时刻 t,物体在恒定加速度下的速度 (v) 描述为:

v = v0 + at

其中 v0 是初速度,a 是加速度。在您的情况下,最终速度为零(物体停止),因此我们可以求解 t:

t = -v0/a

为了找到行进的总差,我们对速度(第一个方程)随时间进行积分。我已经很多年没有做过积分了,但我很确定这个结果是:

d = v0t + 1/2 * at^2

我们可以用我们之前开发的 t 的方程来代替:

d = v0^2/a + 1/2 * v0^2 / a

以及 v0 的解:

v0 = sqrt(-2ad)

或者,以一种更编程语言的格式:

initialVelocity = sqrt( -2 * acceleration * distance );

在这种情况下,加速度是负值(物体正在减速),我假设它是恒定的,否则这会变得更加复杂。

如果您想在步骤有限的循环中使用它,则需要小心一点。循环的每次迭代代表一段时间。物体的移动量等于平均速度乘以时间长度。迭代时间长度等于 1 的示例循环将如下所示:

position = 0;
currentVelocity = initialVelocity;
while( currentVelocity > 0 )
{
    averageVelocity = currentVelocity + (acceleration / 2);
    position = position + averageVelocity;
    currentVelocity += acceleration;
}

This is a simple kinematics problem.

At some time t, the velocity (v) of an object under constant acceleration is described by:

v = v0 + at

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:

t = -v0/a

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:

d = v0t + 1/2 * at^2

We can substitute in the equation for t we developed ealier:

d = v0^2/a + 1/2 * v0^2 / a

And the solve for v0:

v0 = sqrt(-2ad)

Or, in a more programming-language format:

initialVelocity = sqrt( -2 * acceleration * distance );

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:

position = 0;
currentVelocity = initialVelocity;
while( currentVelocity > 0 )
{
    averageVelocity = currentVelocity + (acceleration / 2);
    position = position + averageVelocity;
    currentVelocity += acceleration;
}
要走干脆点 2024-09-01 13:47:51

如果要移动设定距离,请使用以下命令:

alt text

If you want to move a set distance, use the following:

alt text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文