为了更好地理解向量的工作原理,我正在尝试创建一个非常简单的模拟,模拟地球绕太阳运动。目前,我只想让地球在圆形轨道上绕太阳运动,不考虑任何物理定律。
我以为我的做法会有效,但实际上它创造了一种类似于斐波那契螺旋线的运动。
我的计算错在哪里?
我以为我的做法会有效,但实际上它创造了一种类似于斐波那契螺旋线的运动。
// initial positions
vec2 sun(0.0,0.0);
vec2 earth(10.0,0.0);
while(true) {
vec2 earthToSun = normalize(sun - earth); // this is the vector 'pointing from the earth towards the sun'
vec2 speedVector = vec2(-earthToSun.y, earthToSun.x); // this is the vector perpendicular to the earthToSun vector
earth = earth + earthToSun + speedVector; // move the earth along the resulting vector
}
我的计算错在哪里?
earth = earth + earthToSun + speedVector;
将地球向太阳方向移动1个单位,并向垂直方向移动1个单位。这不是一个圆形轨道。 - nullptrt
,以及给定太阳
的位置、地球
的位置和地球速度
,您可以通过以下方式近似计算新的地球位置和速度:加速度=K*normalize(太阳-地球);地球=地球+地球速度*t+加速度*t*t/2.0;地球速度=地球速度+t*加速度
,其中K
是某个常数。但由于模拟的离散性质,地球很快就会撞上太阳(或者飘走)。 - nullptr