In this paper, we present an inverse optimal control-based transfer of motions from human experiments to humanoid robots and apply it to walking in constrained environments. To this end, we introduce a 3D template model, which describes motion on the basis of center-of-mass trajectory, foot trajectories, upper-body orientation, and phase duration. Despite its abstract architecture, with prismatic joints combined with damped series elastic actuators instead of knees, the model (including dynamics and constraints) is suitable for describing both human and humanoid locomotion with appropriate parameters. We present and apply an inverse optimal control approach to identify optimality criteria based on human motion capture experiments. The identified optimal strategy is then transferred to a humanoid robot template model for gait generation by solving an optimal control problem, which takes into account the properties of the robot and differences in the environment. The results of this step are the center-of-mass trajectory, the foot trajectories, the torso orientation, and the single and double support phase durations for a sequence of steps, allowing the humanoid robot to walk within a new environment. In a previous paper, we have already presented one computational cycle (from motion capture data to an optimized robot template motion) for the example of walking over irregular stepping stones with the aim of transferring the motion to two very different humanoid robots (iCub@Heidelberg and HRP-2@LAAS). This study represents an extension, containing an entirely new part on the transfer of the optimized template motion to the iCub robot by means of inverse kinematics in a dynamic simulation environment and also on the real robot.