(x0, v0, t1, t)
| 1 | // Calculate the position based on the current position, speed and time: |
| 2 | // https://www.wolframalpha.com/input/?i=x+%3D+2+*+t+%5E+3+-+3+*+t+%5E+2+%2B+1+from+t+%3D+0+to+t+%3D+1 |
| 3 | const position = (x0, v0, t1, t) => { |
| 4 | const a = (v0 * t1 + 2 * x0) / t1 ** 3; |
| 5 | const b = -(2 * v0 * t1 + 3 * x0) / t1 ** 2; |
| 6 | const c = v0; |
| 7 | const d = x0; |
| 8 | return a * t ** 3 + b * t ** 2 + c * t + d; |
| 9 | }; |
| 10 | |
| 11 | // Calculate the speed based on the current position, speed and time: |
| 12 | const speed = (x0, v0, t1, t) => { |