在有关开普勒第二定律的JavaScript动画中,实现速度变化的问题

时间:2018-11-26 05:21:19

标签: javascript html canvas requestanimationframe

我正在使用HTML画布在JavaScript中制作动画,以模拟开普勒针对学校项目的第二定律。这是了解开普勒第二定律的链接。 https://www.windows2universe.org/the_universe/uts/kepler2.html

开普勒第二定律基本上规定,如果两个点之间的时间差相等,则由两对时间点形成的三角形的面积相等。

此外,行星绕太阳的速度在靠近太阳时会增加,而在离太阳越远时速度会降低。我们可以通过将一些数字除以与太阳平方的距离或v = 50000 / r ^ 2来关联。

对于动画,我正在使用windowRequestAnimationFrame。为了实现实际的动画效果,我使用了极坐标系统。 http://mathworld.wolfram.com/PolarCoordinates.html

我将角度乘以时间对象来调制角度。然后我将其乘以速度。

现在继续讨论实际问题。为了使变化的速度在行星靠近太阳时增大,而在远离太阳时减小,我需要极角来进行计算,但是,我将速度乘以该角。 如何通过变化的角度更新速度?

我觉得好像有一个我无法掌握的简单解决方案。我有指向完整功能的完整代码的链接,可以在浏览器中运行它。 https://drive.google.com/file/d/1EoDgzoSVFDJ-hJMXuA47rBwjQ9vMQFbD/view?usp=sharing

谢谢您的考虑。

    // Initial Angle Values

    var Ang1 = Math.PI;
    var Ang2 = 2 * Math.PI;



  // Initial Distances from the center of the ellipse

    var distance = Distance(Ang1)
    var distance2 = Distance(Ang2)

// X,Y coordinates derived from the distance using sin,cos functions

    var line1_x = orbit.centerx +(distance *  Math.cos(Ang1))
    var line1_y = orbit.centery +(distance *  Math.sin(Ang1))
    var line3_x = orbit.centerx +(distance2 *  Math.cos(Ang2))
    var line3_y = orbit.centery + (distance2 *  Math.sin(Ang2))


// Initial Distance from the sun using the distance formula
    var focalDistance1 = coordDistance(line1_x,line1_y,sun_x,sun_y)
    var focalDistance2 = coordDistance(line3_x,line3_y,sun_x,sun_y)


// Initial velocityies calculated using distance from the sun
    var velocity1 = 50000/Math.pow(focalDistance1,2)
    var velocity2 = 50000/Math.pow(focalDistance2,2)









// Multiplying the initial angles by time to animate and velocity to speed up
    var orbitAngle = ((Ang1/60)*time.getSeconds() + (Ang1/60000)* time.getMilliseconds())* velocity1;
    var orbitAngle3 = ((Ang2/60)*time.getSeconds() + (Ang2/60000)* time.getMilliseconds())* velocity2;

// The polar angle coords of the point ahead by the time interval, multiplying by time to animate and velocity to speed up
    var orbitAngle2 = (   ((Ang1/60) * (time.getSeconds()+timeInterval)) + ((Ang1/60000)*(time.getMilliseconds()+timeInterval*1000))) * velocity1;
    var orbitAngle4 = ( ((Ang2/60) * (time.getSeconds()+timeInterval)) + ((Ang2/60000)*(time.getMilliseconds()+timeInterval*1000))) * velocity2;








    //Animating time interval positions using distance and angle
    var distance = Distance(orbitAngle)
    var distance2 = Distance(orbitAngle2)
    var distance3 = Distance(orbitAngle3)

    var distance4 = Distance(orbitAngle4)



    var line1_x = orbit.centerx +(distance *  Math.cos(orbitAngle))
    var line1_y = orbit.centery +(distance *  Math.sin(orbitAngle))
    var line2_x = orbit.centerx +(distance2 *  Math.cos(orbitAngle2))
    var line2_y = orbit.centery + (distance2 *  Math.sin(orbitAngle2))

    var line3_x = orbit.centerx + (distance3 *  Math.cos(orbitAngle3))
    var line3_y = orbit.centery + (distance3 *  Math.sin(orbitAngle3))
    var line4_x = orbit.centerx +(distance4 *  Math.cos(orbitAngle4))
    var line4_y = orbit.centery + (distance4 *  Math.sin(orbitAngle4))


    var focalDistance1 = coordDistance(line1_x,line1_y,sun_x,sun_y);
    var focalDistance2 = coordDistance(line3_x,line3_y,sun_x,sun_y);

    var velocity1 = 50000/Math.pow(focalDistance1,2)
    var velocity2 = 50000/Math.pow(focalDistance2,2)

0 个答案:

没有答案