use a off-the-shelf physics engine, newton is good.