Find out the acceleration to get to the target position at 0 speed?

I am trying to make my simulation stop at a certain point. I have a start position, end position, current speed and time that I would like to take in order to get there. Because:

d = vt + (at^2)/2 

I realized that

 d = (end - start) a = 2(d - vt) / t^2 

but my endpoint is off when I start it. I tried using two simple updates, first:

 v += a * dt d += v * dt 

and second:

 d += v * dt + a * dt * dt / 2; v += a * dt; 

if that matters. The position in this case is 1d, so there is no need for crazy vector material. Any help would be greatly appreciated :) Thank you!

(Edit: formatting) (Edit2: fixed update # 2) (Edit3: now updates now show dt instead of t)

+4
source share
3 answers

We start with x_start (and t = 0) at a speed of v_start, and we want to end with x_end at zero speed.

Since we have constant acceleration, the average speed will be v_start/2 , which means that we will reach x_end at t_end = (x_end - x_start) / (v_start / 2) .

Ok, then we can use x(t) = x_start + v_start * t + at^2/2 . As a validation check, connect t = 0 and make sure you get x = x_start.

Then connect t_end and you can decide for a. I get -v^2/(2D) , where D is x_end - x_start . A negative sign means that you are slowing down, not accelerating.

If you connect this to the original function, you will get:

 x(t) = x_start + v_start * t - (v^2/4D) * t^2 

If you have a counter that tells you the value of t (which will range from 0 to t_end), you can simply move the object to the desired position at every moment.

Or (and this may make more sense, depending on the language, environment, etc.), you can calculate the instantaneous speed of each time, and then the instantaneous position, following the answer of CoderTao.

+2
source

One possible problem; which is not clear from what you have written so far, is that the equations:

 v+=a*t d+=v*t ... d+=v*t + a*t*t/2 v+=a*t 

Must be:

 v+=a*dt d+=v*dt ... d+=v*dt + a*dt*dt/2 v+=a*dt 

Where dt is the time difference since the last update. It would be helpful to have a little more information - surrounding code, examples of inputs / outputs, etc.

0
source

Why are you changing the formula of physics? Just change the acceleration so that the object stops where you want.

The required acceleration is what you gave:

 a = 2(d - vt) / t^2 

Just assign a in your code when you want to start stopping it.

0
source

Source: https://habr.com/ru/post/1301163/


All Articles