We utilize known exact analytic solutions of perfect fluid hydrodynamics to analytically calculate the polarization of baryons produced in heavy ion collisions. Assuming local thermodynamical equilibrium also for spin degrees of freedom, baryons get a net polarization at their formation (freeze-out). This polarization depends on the time evolution of the Quark-Gluon Plasma (QGP), which can be described as an almost perfect fluid. By using exact analytic solutions, we thus can analyze the necessity of rotation (and vorticity) for non-zero net polarization. In this paper we give the first analytical calculations for the polarization four-vector. We use two hydrodynamical solutions; one is the spherically symmetric Hubble flow (a somewhat oversimplified model, to demonstrate the methodology). The other solution which we use is a somewhat more involved one that corresponds to a rotating and accelerating expansion, and is thus well suited to investigate some main features of the time evolution of the QGP created in peripheral heavy-ion collisions (although there are still many numerous features of a real collision geometry that are beyond the reach of this simple model). Finally we illustrate and discuss our results on the polarization.