// TBD: too much passing around of the Physics object. Probably better if // it was static. there is no way to individually set the kfr and friction of the // surfaces since they are calculated here from properties of the Physics // object. Also, review for too much object creation public virtual Vector ResolveCollision( Vector normal, Engine engine) { // get the velocity Vector vel = curr.MinusNew( prev ); double sDotV = normal.Dot( vel ); // compute momentum of particle perpendicular to normal Vector velProjection = vel.MinusNew( normal.MultNew( sDotV ) ); Vector perpMomentum = velProjection.MultNew( engine.CoeffFric ); // compute momentum of particle in direction of normal Vector normMomentum = normal.MultNew( sDotV * engine.CoeffRest ); Vector totalMomentum = normMomentum.PlusNew( perpMomentum ); // set new velocity w/ total momentum Vector newVel = vel.MinusNew( totalMomentum ); // project out of collision curr.Plus( mtd ); // apply new velocity prev = curr.MinusNew( newVel ); return newVel; }
private double CalcTheta( Vector pa, Vector pb, Vector pc ) { Vector AB = new Vector( pb.X - pa.X, pb.Y - pa.Y ); Vector BC = new Vector( pc.X - pb.X, pc.Y - pb.Y ); double dotProd = AB.Dot( BC ); double crossProd = AB.Cross( BC ); return Math.Atan2( crossProd, dotProd ); }