计算机编程/物理学/加速物体的位置函数(恒定加速度)
外观
加速物体的位移是一个数学函数,表示为
- 如果 a 是恒定值。
a 是加速度,v 是初始速度,t 是时间,s 是起始位置
它在各种编程语言中都有表示,如下所示
; eax = a, ebx = v, ecx = t, edx = s push edx mul ecx mul ecx shr eax,1 add DWORD PTR [esp],eax mov eax,ebx mul ecx add DWORD PTR [esp],eax pop eax
somewhere in the data section: a dd 0.0 ; m*s^-2 s dd 0.0 ; m v dd 0.0 ; m*s^-1 t dd 0.0 ; s half dd 0.5 ; scalar code: push 40000000h fld DWORD PTR [esp] fld t fyl2x fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 fadd fscale fstp st(1) fld a fmul fld half fmul fld v fld t fmul fadd fld s fadd add esp,4 ffree st(0)
inline float PositionofAcceleratingBody(float a, float v, float t, float s) { return .5 * a * t * t + v * t + s; }
template<class Vector,class Number> inline Vector PositionofAcceleratingBody(Vector a,Vector v0,Vector s0,Number t) { return (0.5*a*t+v0)*t+s0; }
function PositionofAcceleratingBody(real a, v, t, s): real; begin result := .5 * a * t * t + v * t + s; end;
function PositionofAcceleratingBody($a, $v, $t, $s) { return .5 * $a * $t * $t + $v * $t + $s; }
public double positionOfAcceleratingBody(double a, double v, double t, double s){ return a * t * t / 2 + v * t + s; }
def positionOfAcceleratingBody(a, v, t, s): return .5 * a * (t ** 2) + v * t + s