Theory of coherent transition radiation generated by ellipsoidal electron bunches