(N/A) Consider an electric dipole with charges $-q$ and $+q$ separated by a distance $2a$,placed in a uniform electric field $\overrightarrow{E}$.
The forces acting on the charges are $+q\overrightarrow{E}$ and $-q\overrightarrow{E}$,which are equal and opposite,forming a couple that exerts a torque $\tau = \vec{p} \times \overrightarrow{E}$,where $\vec{p} = q(2\vec{a})$ is the dipole moment.
The magnitude of the torque is $\tau = pE \sin \theta$,where $\theta$ is the angle between $\vec{p}$ and $\overrightarrow{E}$.
To rotate the dipole against this torque by an infinitesimal angle $d\theta$,an external work $dW$ must be done:
$dW = \tau_{ext} d\theta = pE \sin \theta d\theta$.
The potential energy $U$ is defined as the work done in rotating the dipole from an initial angle $\theta_0$ to a final angle $\theta$:
$U = \int_{\theta_0}^{\theta} pE \sin \theta' d\theta' = pE [-\cos \theta']_{\theta_0}^{\theta} = pE(\cos \theta_0 - \cos \theta)$.
Taking the reference position at $\theta_0 = 90^\circ$ (where $\cos 90^\circ = 0$),the potential energy is:
$U(\theta) = -pE \cos \theta = -\vec{p} \cdot \overrightarrow{E}$.