We show how the St.Venant compatibility relations for strain in three
dimensions lead to twinning for the cubic to tetragonal transition in
martensitic materials within a Ginzburg-Landau model in terms of the six
components of the symmetric strain tensor. The compatibility constraints
generate an anisotropic long-range interaction in the order parameter
(deviatoric strain) components. In contrast to two dimensions, the free energy
is characterized by a "landscape" of competing metastable states. We find a
variety of textures, which result from the elastic frustration due to the
effects of compatibility. Our results are also applicable to structural phase
transitions in improper ferroelastics such as ferroelectrics and
magnetoelastics, where strain acts as a secondary order parameter