Collision of circular objects

老子叫甜甜 提交于 2019-11-28 12:43:08

问题


I'm going to develop carom board game. I'm having the problem with the collision of two pieces. How to find the collision point of two pieces. And then how to find the angle and distance the pieces travel after collision.I found the solution of the collision point at circle-circle collision. here the solution is described with trigonometry, but I want the solution with vector math. With which the problem of the distance covered after collision will also be solve easily.


回答1:


You do not need to find the collision point for the collision computation itself. To detect a collision event, you only need to compare the distance of the centers go the sum of radii

sqrt(sqr(x2-x1)+sqr(y2-y1))<=r1+r2

or

dx*dx+dy*dy <= (r1+r2)*(r1+r2)

where (x1,y1) and (x2,y2) are the positions of disks 1 (with mass m1, radius r1 and velocity (vx1,vy1)) and 2. Differences are always 2 minus 1, dx=x2-x1 etc.


You will almost never get that the collision happens at the sample time of the time discretisation. With the above formula, the circles already have overlap. Depending on time step and general velocities this may be negligible or can result in severe over-shooting. The following simple computation assumes slow motion, i.e., very small overlap during the last time step.


The only thing that happens in the fully elastic collision of non-rotating disks is a change in velocity. This change has to happen only once, when further movement would further reduce the distance, i.e., if

dx*dvx+dy*dvy < 0

where dvx=vx2-vx1 etc.

Using these ideas, the computation looks like this (see https://stackoverflow.com/a/23193044/3088138 for details)

dx = x2-x1; dy = y2-y1;
dist2 = dx*dx + dy*dy;
R = r1+r2;

if ( dist2 <= R*R )
{
    dvx=vx2-vx1; dvy=vy2-vy1;
    dot = dx*dvx + dy*dvy;

    if ( dot < 0 )
    {
        factor = 2/(m1+m2)*dot/dist2;
        vx1 += m2*factor*dx;
        vy1 += m2*factor*dy;
        vx2 -= m1*factor*dx;
        vy2 -= m1*factor*dy;
    }
}


来源:https://stackoverflow.com/questions/28122594/collision-of-circular-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!