【发布时间】:2015-03-03 09:09:12
【问题描述】:
我正在开发一个显示移动划艇的小程序。下面是一个简单的示例代码(Python 2.x):
import time
class Boat:
def __init__(self, pace, spm):
self.pace = pace #velocity of the boat in m/s
self.spm = spm #strokes per minute
self.distance = 0 #distance travelled
def move(self, deltaT):
self.distance = self.distance + (self.pace * deltaT)
boat1 = Boat(3.33, 20)
while True:
boat1.move(0.1)
print boat1.distance
time.sleep(0.1)
如您所见,船的速度和行数每分钟划动数次。每次调用move(deltaT)方法时,都会根据节奏移动一定的距离。
上面的船只是以恒定的速度行驶,这是不现实的。真正的划艇在划桨开始时加速,然后在桨叶离开水面后减速。网上有很多图表显示了典型的划船曲线(这里显示的是力量,速度看起来很相似):
步速应该随着时间的推移保持不变,但在击球过程中应该会发生变化。
将恒定速度变为(至少基本上)类似于更逼真的划船划船的曲线的最佳方法是什么?
注意:关于如何更好地标记这个问题的任何想法?是算法问题吗?
【问题讨论】:
-
使用样条插值,例如,来自 SciPy。
-
参见 SE 网站了解统计信息stats.stackexchange.com
-
以及ggplot库中的平滑变换stat_smooth。
标签: python plot spline smoothing