天天看點

python 軌迹分析_Python語言:程式代碼分析鉛球運動軌迹

鉛球也是體育競技中一種項目,在比賽時通常。通過鉛球運動的遠近,來決定輸赢。

鉛球運動距離,我們也可以程式設計來進行分析。通過把速度數值和力量方向,角度等參數輸入進去。

最後應用程式就能得到鉛球運動的距離,來預判奪冠的結果。

python 軌迹分析_Python語言:程式代碼分析鉛球運動軌迹

鉛球運動軌迹,程式設計代碼如下:

from math import sin, cos, radians class Projectile: def __init__(self, angle, elocity, height):

#根據給定的發射角度、初始速度和位置建立一個投射體對象

self.xpos = 0.0

self.ypos = height theta = radians(angle)

self.xel = elocity * cos(theta)

self.yel = elocity * sin(theta)

def update(self, time): #更新投射體的狀态

self.xpos = self.xpos + time * self.xel

yell = self.yel - 9.8 * time

self.ypos = self.ypos + time * (self.yel + yell) / 2.0 self.yel = yell def getY(self): #傳回投射體的角度

return self.ypos def getX(self): #傳回投射體的距離

return self.xpos

這段程式中輸入的參數不同,得到運動距離也不同。但實際比賽中任何可能都有發生的,畢竟人的力量是無限可能的。

請大家多多和收藏,下一篇文章帶來更精彩的知識分享!