如何计算在一定距离内达到一定速度所需的减速度?

发布于 2024-07-26 04:07:31 字数 1238 浏览 4 评论 0原文

我已经尝试了典型的物理方程,但它们都不起作用,因为这些方程处理恒定的加速度,而我的方程需要改变才能正常工作。 基本上,我有一辆车可以以很大的速度行驶,并且在到达路径终点时需要在给定的距离和时间内减速并停止。

所以,我有:
V0,或当前速度
Vf,或者我想要达到的速度(通常为 0)
t,或者我想要到达路径终点所需的时间
的距离

d,或者当我从 V0 变为 Vf 时我想要计算
a,或从 V0 到 Vf 所需的加速度。

这成为一个特定于编程的问题的原因是,当汽车不断停止时,a 需要在每个时间步重新计算。 因此,V0 不断地更改为上一个时间步的 V0 加上 上一个时间步计算的 a。 所以本质上它会开始缓慢停止,然后最终会突然停止,有点像现实生活中的汽车。

编辑:
好的,感谢您的精彩回复。 我所需要的很多只是思考这个问题的一些帮助。 现在我已经从大家那里得到了更多想法,让我说得更具体一些:

我有一辆汽车 c,距目的地 64 像素,所以 d =64 。 它以每个时间步 2 像素 的速度行驶,其中时间步为 1/60 秒。 我想找到加速度 a,使其在行进 d 时达到每时间步 0.2 像素的速度。
d = 64 //距离
V0 = 2 //初速度(以ppt为单位)
Vf = 0.2 //final Velocity (in ppt)

另外,由于这种情况发生在游戏循环中,因此变量 delta 会传递给每个动作,即 最后一个时间步长的 1/60 的倍数。 换句话说,如果花费了 1/60 秒,那么 delta 就是 1.0,如果花费了 1/30 秒,那么 delta 就是 0.5。 在实际应用加速度之前,将其乘以该增量值。 类似地,在汽车再次移动之前,其速度会乘以增量值。 这是非常标准的东西,但这可能是导致我的计算出现问题的原因。

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.

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

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

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:

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)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

梦回梦里 2024-08-02 04:07:31

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

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

编辑:

编辑后,让我尝试衡量您需要什么...

如果您采用此公式并插入您的数字,您将获得 -0,0309375 的恒定加速度。 现在,我们继续称这个结果为“a”。

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

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

其中 Sd 是当前帧/时刻/sum_of_deltas 距起始位置的当前距离,Vi 是起始速度,t 是自起始以来的时间。

这样,您的减速度恒定的,但即使它是线性的,您的速度也会适应您的限制。

如果你想要非线性减速度,你可以找到一些非线性插值方法,并且插值不是加速度,而是简单地插值两点之间的位置。

location = non_linear_function(time);

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)

EDIT:

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

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

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);
冷清清 2024-08-02 04:07:31

您给出的四个约束对于线性系统(具有恒定加速度的线性系统)来说太多了,其中任何三个变量都足以计算加速度,从而确定第四个变量。 然而,该系统对于完全通用的非线性系统来说是远远不够的——可能有无数种方法可以随时间改变加速度,同时满足给定的所有约束。 您能否更好地指定加速度应随时间变化的曲线类型?

使用 0 索引表示“开始时”,1 表示“结束时”,D 表示 Delta 表示“变化”,给定线性变化的加速度,

  a(t) = a0 + t * (a1-a0)/Dt

其中 a0 和 a1 是我们要计算以满足所有条件的两个参数我计算了各种约束(如果没有失误,因为我都是手工完成的):

DV = Dt * (a0+a1)/2
Ds = Dt * (V0 + ((a1-a0)/6 + a0/2) * Dt)

给定 DV、Dt 和 Ds 都给定,这在未知数 a0 和 a1 中留下了 2 个线性方程,因此您可以求解这些(但我将这些内容保留在这种形式中,以便更容易地仔细检查我的推导!!!)。

如果您在每一步都应用正确的公式来计算空间和速度的变化,那么无论是一次性计算 a0 和 a1,还是根据剩余的 Dt、Ds 和 DV 在每一步重新计算它们,都没有什么区别。

The four constraints you give are one too many for a linear system (one with constant acceleration), where any three of the variables would suffice to compute the acceleration and thereby determine the fourth variables. However, the system is way under-specified for a completely general nonlinear system -- there may be uncountably infinite ways to change acceleration over time while satisfying all the constraints as given. Can you perhaps specify better along what kind of curve acceleration should change over time?

Using 0 index to mean "at the start", 1 to mean "at the end", and D for Delta to mean "variation", given a linearly changing acceleration

  a(t) = a0 + t * (a1-a0)/Dt

where a0 and a1 are the two parameters we want to compute to satisfy all the various constraints, I compute (if there's been no misstep, as I did it all by hand):

DV = Dt * (a0+a1)/2
Ds = Dt * (V0 + ((a1-a0)/6 + a0/2) * Dt)

Given DV, Dt and Ds are all given, this leaves 2 linear equations in the unknowns a0 and a1 so you can solve for these (but I'm leaving things in this form to make it easier to double check on my derivations!!!).

If you're applying the proper formulas at every step to compute changes in space and velocity, it should make no difference whether you compute a0 and a1 once and for all or recompute them at every step based on the remaining Dt, Ds and DV.

未央 2024-08-02 04:07:31

如果您试图在方程中模拟与时间相关的加速度,则意味着您应该假设这一点。 您必须将 F = ma 与加速度方程积分,仅此而已。 如果加速度不是恒定的,您只需求解一组方程组,而不仅仅是一个方程组。

因此,现在您实际上必须同时积分三个向量方程:一个对应于位移、速度和加速度的每个分量,或者总共九个方程。 作为时间函数的力将成为您问题的输入。

如果您假设一维运动,则只剩下三个联立方程。 速度和位移都非常简单。

If you're trying to simulate a time-dependent acceleration in your equations, it just means that you should assume that. You have to integrate F = ma along with the acceleration equations, that's all. If acceleration isn't constant, you just have to solve a system of equations instead of just one.

So now it's really three vector equations that you have to integrate simultaneously: one for each component of displacement, velocity, and acceleration, or nine equations in total. The force as a function of time will be an input for your problem.

If you're assuming 1D motion you're down to three simultaneous equations. The ones for velocity and displacement are both pretty easy.

秋凉 2024-08-02 04:07:31

在现实生活中,汽车的制动能力取决于制动踏板上的压力、正在进行的任何发动机制动、路面状况等:此外,当汽车真正停止时,最后会出现“抓地”现象。 建模很复杂,您不太可能在编程网站上找到好的答案。 找一些汽车工程师。

除此之外,我不知道你还要求什么。 您是否正在尝试确定制动时间表? 比如滑行时有一定的减速度,然后踩刹车? 在实际驾驶中,这些操作通常不考虑时间,而是考虑距离。

据我所知,你的问题是你没有要求任何具体的东西,这表明你真的还没有弄清楚你真正想要什么。 如果您能提供一个示例用途,我们可能会为您提供帮助。 事实上,您已经提供了一个问题的概要,该问题要么是过度确定的,要么是约束不足的,而我们对此无能为力。

In real life, a car's stopping ability depends on the pressure on the brake pedal, any engine braking that's going on, surface conditions, and such: also, there's that "grab" at the end when the car really stops. Modeling that is complicated, and you're unlikely to find good answers on a programming website. Find some automotive engineers.

Aside from that, I don't know what you're asking for. Are you trying to determine a braking schedule? As in there's a certain amount of deceleration while coasting, and then applying the brake? In real driving, the time is not usually considered in these maneuvers, but rather the distance.

As far as I can tell, your problem is that you aren't asking for anything specific, which suggests that you really haven't figured out what you actually want. If you'd provide a sample use for this, we could probably help you. As it is, you've provided the bare bones of a problem that is either overdetermined or way underconstrained, and there's really nothing we can do with that.

榆西 2024-08-02 04:07:31

如果您需要以线性加速度在 1m 内从 10m/s 变为 0m/s,则需要 2 个方程。
首先求出停止所需的时间(t)。

v0 = initial velocity
vf = final velocity
x0 = initial displacement
xf = final displacement
a = constant linear acceleration

(xf-x0)=.5*(v0-vf)*t
t=2*(xf-x0)/(v0-vf)
t=2*(1m-0m)/(10m/s-0m/s)
t=.2seconds

next to calculate the linear acceleration between x0 & xf

(xf-x0)=(v0-vf)*t+.5*a*t^2
(1m-0m)=(10m/s-0m/s)*(.2s)+.5*a*((.2s)^2)
1m=(10m/s)*(.2s)+.5*a*(.04s^2)
1m=2m+a*(.02s^2)
-1m=a*(.02s^2)
a=-1m/(.02s^2)
a=-50m/s^2

in terms of gravity (g's)

a=(-50m/s^2)/(9.8m/s^2)
a=5.1g over the .2 seconds from 0m to 10m

if you need to go from 10m/s to 0m/s in 1m with linear acceleration you need 2 equations.
first find the time (t) it takes to stop.

v0 = initial velocity
vf = final velocity
x0 = initial displacement
xf = final displacement
a = constant linear acceleration

(xf-x0)=.5*(v0-vf)*t
t=2*(xf-x0)/(v0-vf)
t=2*(1m-0m)/(10m/s-0m/s)
t=.2seconds

next to calculate the linear acceleration between x0 & xf

(xf-x0)=(v0-vf)*t+.5*a*t^2
(1m-0m)=(10m/s-0m/s)*(.2s)+.5*a*((.2s)^2)
1m=(10m/s)*(.2s)+.5*a*(.04s^2)
1m=2m+a*(.02s^2)
-1m=a*(.02s^2)
a=-1m/(.02s^2)
a=-50m/s^2

in terms of gravity (g's)

a=(-50m/s^2)/(9.8m/s^2)
a=5.1g over the .2 seconds from 0m to 10m
早乙女 2024-08-02 04:07:31

问题要么是过度约束,要么是约束不足(a 不是常数?a 是否有最大值?)或不明确。

最简单的公式是 a=(Vf-V0)/t

编辑:如果时间不受约束,距离 s 受约束,并且加速度恒定,则相关公式为 s = (Vf+V0)/2 * t, t =(Vf-V0)/a 简化为 a = (Vf2 - V02) / (2s)。

Problem is either overconstrained or underconstrained (a is not constant? is there a maximum a?) or ambiguous.

Simplest formula would be a=(Vf-V0)/t

Edit: if time is not constrained, and distance s is constrained, and acceleration is constant, then the relevant formulae are s = (Vf+V0)/2 * t, t=(Vf-V0)/a which simplifies to a = (Vf2 - V02) / (2s).

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