Spatial engineering of polarization as a new method of beam shaping is analyzed by using scalar diffraction theory. For the one-dimensional case, it is shown that the smallest flattop far-field distribution can be obtained by adopting a linear polarization that changes direction as a linear function of location in the pupil plane. The resulting light field is functionally equivalent to a cosinusoidal function modulation of the wavefront but maintains high efficiency. This polarization beam shaping technique proves to be highly useful in applications where diffraction effects need to be taken into account. The extension of this technique to two-dimensional beam shaping is also demonstrated.