One of the main challenges posed by the next space systems generation is the high level of autonomy they will require. Hazard Detection and Avoidance is a key technology in this context. An adaptive guidance algorithm for landing that updates the trajectory to the surface by means of an optimal control problem solving is here presented. A semi-analytical approach is proposed. The trajectory is expressed in a polynomial form of minimum order to satisfy a set of boundary constraints derived from initial and final states and attitude requirements. By imposing boundary conditions, a fully determined guidance profile is obtained, function of a restricted set of parameters. The guidance computation is reduced to the determination of these parameters in order to satisfy path constraints and other additional constraints not implicitly satisfied by the polynomial formulation. The algorithm is applied to two different scenarios, a lunar landing and an asteroidal landing, to highlight its general validity. verify the versatility of the algorithm in realistic cases, by the introduction of attitude control systems, thrust modulation, and navigation errors. The proposed approach proved to be flexible and accurate, granting a precision of a few meters at touchdown.