A General Formulation for Path Constrained Time-Optimized Trajectory Planning with Environmental and Object Contacts