使用守恒和运动公式在P5.js中的水平滑动对象之间转换能量时是否存在问题?

时间:2019-11-04 20:06:28

标签: physics p5.js

我是编码物理学的新手(虽然编码能力很差,但是我很喜欢),所以我决定第一次尝试这样简单的方法: https://www.maths.tcd.ie/~lebed/Galperin.%20Playing%20pool%20with%20pi.pdf

我发现了此视频中的链接:

https://www.youtube.com/watch?v=jsYwFizhncE

我试图在P5.js中重新创建这种运动(如果它们不能帮助我,确切的数字对我来说就不重要了,只是运动),我已经非常接近但随机地遇到碰撞一切都破了,速度疯了。

这是我尝试执行的简短简短的“伪代码”: (这是我努力的主要部分,因此并不需要我的实际代码)

// Get menu input
    input = cin.get();
    if (input == '\n') {    // Check if user hot entered, assign value if so
        input = 0; 
    } 
//else {      // If not, do it normally
//         input = cin.get();
//     }

我不知道如何保持系统中的总动能等于 动能守恒公式(/公式的常数)

>>>if box2 position < box1 position:  //if they overlap(/collide)
>>>   change velocity of box 1 depending on the kinetic energy and momentum of box2
>>>   change velocity of box 2 depending on the kinetic energy and momentum of box1
>>>If box1 position < 0: //If it hits wall
>>>   box1 velocity = box1 velocity * -1

还有动量守恒:

keCons_Const=(0.5*m1*(velocity1)^2)+(0.5*m2*(velocity2)^2);

我认为自己对此感到困惑的主要原因是因为我不知道如何将速度数字设置为实际的“ m / s”,这使我不满意,就像我正在使用的代码中一样:

momentCons_Const=(m1*velocity1)+(m2*velocity2);

因此,我无法真正查看链接的视频以供参考并查看是否获得了适当的值

但是,我确实知道这两个速度需要根据分数进行更改,可能是这样的:

这里的东西 / keCons_Const

如果可能的话,请不要为我做任何事情,一旦速度等事情弄清楚了,我将可以做一些事情。谢谢!

我的屏幕图像(刚刚意识到您可以添加图像):

0 个答案:

没有答案