This paper presents a mathematical method for generating walking primitives for an anthropomorphic 3D-biped with 12 joints. The corresponding rigid body model includes all masses and inertia tensors. Control torques allowing a symmetrical straight ahead gait with pre-swing, swing and heel-contact are derived by dynamic optimization using a direct collocation approach. The computed torques minimize the absolute value of the mechanical power consumption in the joints of the biped. Zero moment point (ZMP) and friction conditions at the feet ensuring postural stability of the biped, as well as bounds on the joint angles and on the control torques, are treated as constraints. The resulting biped motion is dynamically stable and the overall motion behaviour is remarkably close to that of humans.