# 猫会去哪里？（轨道力学）

16

``````1 0 0 0 -1 0 1000000000 --> 0.83789 -0.54584 0
``````

R. Kap

@R。Kap没关系。`t`以单位时间给出，无论是什么，速度将使用相同的单位。无论是几秒钟还是几小时，答案都是一样的。
soktinpk

`nearly massless cat`那么，猫的确切体重是多少？我们应该只使用`0`这只猫的体重作为价值吗？
R. Kap

@R。卡普是的。但是它仍然受重力影响（通常，牛顿并不认为无质量的物体会受到重力影响）。因此，我们应该认为它的质量任意小，而您的答案实际上是猫的质量变为零时的位置。要点是，行星本身完全不受猫的影响。
soktinpk

2
@soktinpk可能更容易明确地表明中心主体是固定的。
Maltysen '16

6

# Python 3.5 + NumPy，准确，186个字节

``````from math import*
def o(r,v,t):
d=(r@r)**.5;W=2/d-v@v;U=W**1.5;b=[0,t*U+9]
while 1:
a=sum(b)/2;x=1-cos(a);y=sin(a)/U;k=r@v*x/W+d*y*W
if a in b:return k*v-r*x/W/d+r
b[k+a/U-y>t]=a``````

``````>>> from numpy import array
>>> o(array([1,0,0]),array([0,-1,0]),1000000000)
array([ 0.83788718, -0.54584345,  0.        ])
>>> o(array([-1.1740058273269156,8.413493259550673,0.41996042044140003]),array([0.150014367067652,-0.09438816345868332,0.37294941703455975]),7999.348650387233)
array([-4.45269544,  6.93224929, -9.27292488])
``````

R. Kap

1

@miles因为领带是用代码长度打断的，所以打起来很有意义。
Mego

2

# Java脚本

``````function simulate(x, y, z, vx, vy, vz, t) {
var loops = 1884955; // tune this parameter
var timestep = t / loops;
for (var i = 0; i < t; i += timestep) {
var distanceSq = x*x + y*y + z*z; // distance squared from origin
var distance = Math.sqrt(distanceSq);
var forceMag = 1/distanceSq; // get the force of gravity
var forceX = -x / distance * forceMag;
var forceY = -y / distance * forceMag;
var forceZ = -z / distance * forceMag;
vx += forceX * timestep;
vy += forceY * timestep;
vz += forceZ * timestep;
x += vx * timestep;
y += vy * timestep;
z += vz * timestep;
}
return [x, y, z];
}``````

``simulate(1, 0, 0, 0, -1, 0, Math.PI*2) --> [0.9999999999889703, -0.0000033332840909716455, 0]``

``````console.log(simulate(1, 0, 0, 0, -1, 0, 1000000000))
--> [-530516643639.4616, -1000000000.0066016, 0]``````

``````simulate(-1.1740058273269156,8.413493259550673,0.41996042044140003,0.150014367067652,-0.09438816345868332,0.37294941703455975,7999.348650387233)
-->    [-4.528366392498373, 6.780385554803544, -9.547824236472668]
Actual:[-4.452695438880813, 6.932249293597744, -9.272924876103785]``````