A new approach to the inversion problem of dynamical transmission electron
diffraction is described, based on the method of generalized projections in
set theory. An algorithm is described that projects between two sets of co
nstrained scattering matrices. This iterative process can be shown to conve
rge, giving the required structure factors (for some choice of origin) if t
he sets are convex. For the dynamical inversion problem, the set topology i
s that of an N-2 torus, the sets are not convex, and traps are therefore so
metimes encountered. These can be distinguished from solutions, allowing th
e algorithm to be restarted until a solution is found. Examples of successf
ul inversion from simulated multiple-scattering data are given, which there
fore solve the phase problem of electron diffraction for centrosymmetric or
noncentrosymmetric crystal structures. The method may also be useful for t
he three-beam X-ray diffraction problem.