Angle between dipole moment and electric field I was learning the potential energy of a dipole because of torque from Halliday Resnick. In the given diagram, it said that if we move the system anticlockwise then the amount the Work that was done by the torque would be equal to $\displaystyle\int_{90}^θ-pE\sin θdθ$. Where Torque is given by $pΕ\sin θ$. Now potential at $90°$ is considered to be zero hence we get $\displaystyle U=-W=\int_{90}^θpE\sin θdθ$. So we get $U(θ)=-pE\cos θ$.
But when we move the system anticlockwise isn't the angle actually greater than $90°$. So the result we just got is for an angle greater than $90°$. So if we get an angle less than that it should come out positive as $\cos (90+θ)=-\sin θ$. Hence shouldn't it actually be $pE\sin θ$? Where have I gone wrong?

 A: 
$dW=\vec\tau_{_E}\cdot d\vec\varphi>0$ when both $\vec\tau_{_E}=\vec p\times \vec E$ and $d\vec\varphi$ are in the same direction(or if constitute an acute angle), regardless of the choice of the coordinate system. Here, the work done by the electric field is positive in both the cases because both the torque of the field $\vec\tau_{_E}$ and the angular displacement $d\vec\varphi$ are anti-clockwise in both the cases. The only difference between the two cases is a mathematical one, the axis $\varphi$ is measured from.
Potential energy is the work done against the conservative force to move the particle slowly. Hence, the potential energy in both the cases above should be the same (negative) regardless of the choice of coordinate axes. This equivalence is exhibited mathematically as follows:
CASE I: Measuring the angle $\theta$ clockwise from the $x-$axis pointing towards the left.
$$U=-W_{_E}=-\int_{\frac{\pi}2}^{\theta_0} (\vec p \times \vec E)\cdot (d\vec\theta)=\int_{\frac{\pi}2}^{\theta_0} pE\sin\theta\, d\theta=-pE[\cos\theta]_{\frac{\pi}2}^{\theta_0}=-pE\cos\theta_0=-\mathbf p\cdot\mathbf E<0$$
where $|d\vec\theta|=-d\theta\circlearrowleft$, where $d\theta<0$. As a check $W_{_E}=\int_{\frac{\pi}2}^{\theta_0} \underbrace{(\vec p \times \vec E)\cdot (d\vec\theta)}_{\circlearrowleft\ \cdot\ \circlearrowleft}>0$.

CASE II: Measuring the angle anti-clockwise from an axis pointing towards the right.
$$U=-W_{_E}=-\int_{\frac{\pi}2}^{\frac{\pi}2+\theta_0^\prime} (\vec p \times \vec E)\cdot (d\vec\theta)=-\int_{\frac{\pi}2}^{\frac{\pi}2+\theta_0^\prime} pE\sin\theta\, d\theta=pE[\cos\theta]_{\frac{\pi}2}^{\frac{\pi}2+\theta_0^\prime}=pE\cos\left(\frac{\pi}2+\theta_0^\prime\right)=-pE\cos\left[\pi-\left(\frac{\pi}2+\theta_0^\prime\right)\right]=-pE\cos\theta_0=-\mathbf p\cdot\mathbf E<0$$
where $|d\vec\theta|=d\theta\circlearrowleft$, where $d\theta>0$. As a check $W_{_E}=\int_{\frac{\pi}2}^{\frac{\pi}2+\theta_0^\prime} \underbrace{(\vec p \times \vec E)\cdot (d\vec\theta)}_{\circlearrowleft\ \cdot\ \circlearrowleft}>0$.
