07 - Ball to Ball Collision/script.js
//repositions the balls based on the penetration depth and the collision normal

repositions the balls based on the penetration depth and the collision normal
repositions the balls based on the penetration depth and the collision normal
function pen_res_bb(b1, b2){
    let dist = b1.pos.subtr(b2.pos);
    let pen_depth = b1.r + b2.r - dist.mag();
    let pen_res = dist.unit().mult(pen_depth/2);
    b1.pos = b1.pos.add(pen_res);
    b2.pos = b2.pos.add(pen_res.mult(-1));
}
function pen_res_bb ( b1 , b2 ) { let dist = b1 . pos . subtr ( b2 . pos ) ; let pen_depth = b1 . r + b2 . r - dist . mag ( ) ; let pen_res = dist . unit ( ) . mult ( pen_depth / 2 ) ; b1 . pos = b1 . pos . add ( pen_res ) ; b2 . pos = b2 . pos . add ( pen_res . mult ( - 1 ) ) ; }
repositions the balls based on the penetration depth and the collision normal
repositions the balls based on the penetration depth and the collision normal