Python billiards碰撞响应我的公式有些角度问题

时间:2013-01-22 23:07:26

标签: python collision-detection physics billiards

这是我对2个移动球碰撞的台球模拟的碰撞响应代码。我使用牛顿方程定律,然后参数化速度矢量的分量,

Alpha是球1的轨迹 Beta是球2的轨迹 θ是中心线相对于轴的角度

我的想法是在2个球的局部框架中提出碰撞响应的通用公式,然后将其重新投影到我的固定框架中,但我注意到有一些角度问题,我无法弄清楚我的生活应该是什么条件,即阿尔法

最后一点是为了确保碰撞后球不重叠并陷入无限的碰撞循环

    def collision(b1,b2):

        dx=b1.x-b2.x
        dy=b1.y-b2.y
        Theta = atan2(dy,dx)
        Vx1=b1.speedx
        Vy1=b1.speedy


        Vx2=b2.speedx
        Vy2=b2.speedy

        V1 = sqrt((Vx1)**2+(Vx1)**2)
        V2 = sqrt((Vx2)**2+(Vx1)**2)
        Alpha = asin(Vx1/V1)
        Beta = asin(Vx2/V2)


       b1.speedx = (((1-e)/2)*V1*sin(Alpha-Theta) - ((1+e)/2)*V2*sin(Beta-Theta))*sin(Theta) - V1*cos(Alpha-Theta)*cos(Theta)
       b1.speedy = (((1-e)/2)*V1*sin(Alpha-Theta) - ((1+e)/2)*V2*sin(Beta-Theta))*cos(Theta) + V1*cos(Alpha-Theta)*sin(Theta)
       b2.speedx = (((1+e)/2)*V1*sin(Alpha-Theta) - ((1-e)/2)*V2*sin(Beta-Theta))*sin(Theta) + V2*cos(Beta-Theta)*cos(Theta)
       b2.speedy = (((1+e)/2)*V1*sin(Alpha-Theta) - ((1-e)/2)*V2*sin(Beta-Theta))*cos(Theta) - V2*cos(Beta-Theta)*sin(Theta)

1 个答案:

答案 0 :(得分:0)

不要使用asin来计算角度。如果你坚持使用角度(而不是矢量),你应该使用atan2。