如何计算在一定距离上达到一定速度所需的减速度? [英] How to calculate deceleration needed to reach a certain speed over a certain distance?

查看:588
本文介绍了如何计算在一定距离上达到一定速度所需的减速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为此,我尝试了典型的物理方程式,但它们均未真正起作用,因为这些方程式涉及恒定加速度,因此,我的方程式需要进行更改才能正常工作.基本上,我的汽车可以在很大的速度范围内行驶,并且需要减速并在给定的距离和时间停下来,直到它到达路径的尽头.

I've tried the typical physics equations for this but none of them really work because the equations deal with constant acceleration and mine will need to change to work correctly. Basically I have a car that can be going at a large range of speeds and needs to slow down and stop over a given distance and time as it reaches the end of its path.

所以,我有:
V0或当前速度
Vf或我要达到的速度(通常为0)
t,或者我想走到尽头的时间
d,或者当我从V0更改为Vf时要走的距离

So, I have:
V0, or the current speed
Vf, or the speed I want to reach (typically 0)
t, or the amount of time I want to take to reach the end of my path
d, or the distance I want to go as I change from V0 to Vf

我要计算
a或从V0到Vf所需的加速度

I want to calculate
a, or the acceleration needed to go from V0 to Vf

之所以成为特定于编程的问题,是因为随着汽车不断停车,需要在每个时间步长重新计算a.因此,V0将从上一个时间步长plus到上一个时间步长计算出的a始终更改为V0.因此,从本质上讲,它会开始缓慢停止,然后最终会突然停止,就像现实生活中的汽车一样.

The reason this becomes a programming-specific question is because a needs to be recalculated every single timestep as the car keeps stopping. So, V0 constantly is changed to be V0 from last timestep plus the a that was calculated last timestep. So essentially it will start stopping slowly then will eventually stop more abruptly, sort of like a car in real life.


好的,谢谢您的大力响应.我需要的很多只是考虑到这一点而已.现在,我想让您更具体一点,我想从大家那里得到更多的想法:

EDITS:
All right, thanks for the great responses. A lot of what I needed was just some help thinking about this. Let me be more specific now that I've got some more ideas from you all:

我有一辆汽车c距目的地是64 pixels,所以是d=64.它在2 pixels per timestep(timestep is 1/60 of a second)行驶.我想找到加速度a,它将在它行进d时将其速度提高到0.2 pixels per timestep.
d = 64 //distance
V0 = 2 //initial velocity (in ppt)
Vf = 0.2 //final velocity (in ppt)

I have a car c that is 64 pixels from its destination, so d=64. It is driving at 2 pixels per timestep, where a timestep is 1/60 of a second. I want to find the acceleration a that will bring it to a speed of 0.2 pixels per timestep by the time it has traveled d.
d = 64 //distance
V0 = 2 //initial velocity (in ppt)
Vf = 0.2 //final velocity (in ppt)

此外,由于这是在游戏循环中发生的,因此将变量delta传递给每个动作,即multiple of 1/60s that the last timestep took.换句话说,如果花费了1/60秒,则delta为1.0,如果花费了1/30s,则delta为0.5.在实际应用加速度之前,将其乘以该增量值.同样,在轿厢再次移动之前,其速度要乘以增量值.这是很标准的东西,但这可能是导致我的计算出现问题的原因.

Also because this happens in a game loop, a variable delta is passed through to each action, which is the multiple of 1/60s that the last timestep took. In other words, if it took 1/60s, then delta is 1.0, if it took 1/30s, then delta is 0.5. Before acceleration is actually applied, it is multiplied by this delta value. Similarly, before the car moves again its velocity is multiplied by the delta value. This is pretty standard stuff, but it might be what is causing problems with my calculations.

推荐答案

线性加速度a,从起始速度Vi到最终速度Vf的距离d:

Linear acceleration a for a distance d going from a starting speed Vi to a final speed Vf:

a = (Vf*Vf - Vi*Vi)/(2 * d)

编辑:

编辑后,让我尝试确定您的需求...

After your edit, let me try and gauge what you need...

如果采用该公式并输入数字,则常数加速度为-0,0309375.现在,让我们继续将此结果称为"a".

If you take this formula and insert your numbers, you get a constant acceleration of -0,0309375. Now, let's keep calling this result 'a'.

在时间戳(帧)之间需要的实际上不是加速度,而是车辆的新位置,对不对?因此,您使用以下公式:

What you need between timestamps (frames?) is not actually the acceleration, but new location of the vehicle, right? So you use the following formula:

Sd = Vi * t + 0.5 * t * t * a

其中Sd是当前帧/时刻/deltas上距起始位置的当前距离,Vi是起始速度,t是距起始位置的时间.

where Sd is the current distance from the start position at current frame/moment/sum_of_deltas, Vi is the starting speed, and t is the time since the start.

这样,您的减速度恒定,但是即使是线性的,您的速度也会适应您的约束.

With this, your decceleration is constant, but even if it is linear, your speed will accomodate to your constraints.

如果要进行非线性减速度,可以找到一些非线性插值方法,而不是对加速度进行插值,而只需在两点之间定位即可.

If you want a non-linear decceleration, you could find some non-linear interpolation method, and interpolate not acceleration, but simply position between two points.

location = non_linear_function(time);

这篇关于如何计算在一定距离上达到一定速度所需的减速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆