Time-Optimal Trajectory Planning with Interaction with the Environment