Foundations of Position Based Rigid Body Dynamics