代码之家  ›  专栏  ›  技术社区  ›  aleclarson

从减速方程求速度

  •  0
  • aleclarson  · 技术社区  · 9 年前

    假设我们有这个减速方程:

    function getVelocity(elapsedTime, startOffset, initialVelocity, decelerationRate) {
    
      var offset = startOffset +
        (initialVelocity / (1 - decelerationRate)) *
        (1 - Math.exp(-(1 - decelerationRate) * elapsedTime));
    
      return // Answer goes here.
    }
    

    我如何找到 velocity 鉴于 elapsedTime ?

    这个 startOffset 可以是 0 .

    这个 decelerationRate 可以是 0.998 .

    这个 initialVelocity 可以是 0.5 .

    1 回复  |  直到 9 年前
        1
  •  1
  •   Volune    9 年前

    我不确定你对 velocity ,但假设 offset 是一个位置,我认为它是你的函数对时间的导数。

    所以你应该能够找到一次的速度 elapsedTime 使用以下公式:

    return initialVelocity * Math.exp(-(1 - decelerationRate) * time)
    

    我的数学有点生疏,所以请不要犹豫,仔细检查或纠正我。


    第一个答案:

    return (initialVelocity / (1 - decelerationRate)) *
               (1 - decelerationRate) *
               Math.exp(-(1 - decelerationRate) * time)