In this paper, a new approach is proposed to optimize flight trajectories of aerospace vehicles for terrain following and avoidance. In this approach, the problem of trajectory optimization is defined as a minimum-time optimal control problem and is solved by a combined direct method. The used solution method is a combination of direct collocation method, nonlinear programming, differential flatness and B-spline curves. In this method, by using differential flatness, the governing dynamic equations are expressed by the minimum number of state variables in the minimum dimensional space. Also, state variables are approximated by B-spline curves, and control points of these curves are considered as discrete optimization variables of the nonlinear programming problem. By using the proposed approach, the minimum-time flight trajectories are achieved based on the problem dynamic and physical and operational constraints. Because of high solution speed and accuracy, the approach can be used in model predictive control structures for online generation of optimal trajectories. In this paper, a numerical example is presented and solved to demonstrate specifications and capabilities of the proposed approach.