Electrostatic Potential Energy I have read many books on Mechanics and Electrodynamics and the one thing that has confused me about electrostatic potential energy is its derivation .One of the classical derivations is :

$$\newcommand{\newln}{\\&\quad\quad{}} \begin{align}&\int^{r_b}_{r_a}\mathbf{\vec{F}}\cdot d\mathbf{\vec{r}}=-(U_a-U_b) \newln \Rightarrow \int^{r}_{\infty}\mathbf{\vec{F}}\cdot d\mathbf{\vec{r}}=-(U_r-U_\infty) \newln \Rightarrow \int^{r}_{\infty}\mathbf{\vec{F}}\cdot d\mathbf{\vec{r}} =-U_r ~~~~~~~ [U_\infty = 0]\newln \Rightarrow  \int^{r}_{\infty}k\cdot\frac{q.q_o}{r^2}d\mathrm{\mathbf{r}}=-U_r ~~~~~~~ [\textrm{Coulomb's     Law}]\newln \Rightarrow kq\cdot q_o\int^{r}_{\infty}\frac{1}{r^2}d\mathbf{r}=-U_r\newln \Rightarrow kq\cdot q_o\left[\frac{-1}{r} \right]^r_\infty=-Ur\newln\Rightarrow \frac{-kq.q_o}{r}=-U_r\newln \Rightarrow U_r=\frac{kq.q_o}{r}
\end{align} 
$$

My problem is in the fourth line of the derivation. shouldn't there be a $Cos\theta$ term there as it is a dot product.But using it would change the resulting equation to have an extra $Cos \theta$ term being multiplied to it.Why is it not used ? . The direction of the forces have to be defined right?
One more thing - In the derivation it is finally said that the result is sign sensitive but isn't the equation of Coulombic force just for the magnitude?Then how come the result is sign sensitive.
Could Some One give me or direct me to a definition and a derivation that caters to these querrys?
EDIT:


*

*[I saw the proof on Wikipedia it has some thing on my doubt but doesnt seen to use it.It uses cos theta but i cant seem to understand why they used only $\pi$ and not $2\pi$]

*[I know that $Cos\theta$ can be either +1 or -1 depending on the polarity of the charges and that it will be a constant but doing that will change the result altogether : How? :]

  
*
  
*If in the original result you put similar charges you get a positive result .
  
*But in this case if you have similar signs then the cos theta would be -1 as the displacement and the force of repulsion would be anti-paralell.
  

 A: You are right...! There should be a $\cos\theta$ factor. If you choose a path $\mathcal{P}$ from $\infty$ to $r$, then along this path, you have to evaluate 
$$
\mathbf{F} \cdot d\mathbf{r} = |\mathbf{F}| |d\mathbf{r}| \cos\theta
$$
The angle $\theta$ will also depend on where you are on the path compared to the local direction of the force $\mathbf{F}$. True.
But when you learnt that in electrostatics one can define an electric potential, you must also have learnt that this potential is related to the electric field via
$$\mathbf{E} = -\nabla U$$
The reason you can write this way is because the electric field is irrotational, i.e.,
$$\nabla \times \mathbf{E}=0$$
If this makes sense to you, then you must also know that via Stokes theorem the line-integral of $\mathbf{E}$ between two points is independent of the path between those points. Since $\mathbf{F} = q\mathbf{E}$, we have
$$\int_A^B \mathbf{F} \cdot d\mathbf{r}$$
is independent of the path chosen for going from $A$ to $B$. So you can just choose a path such that this $\cos\theta$ factor is a constant. For a point charge, $\mathbf{E}$ will be radially directed from the charge. Choose the path along a radial direction from $\infty$ to $r$. Then $\cos\theta = \pm 1$ depending on the sign of the charge and comes out of the integral.
A: You don't need the $\cos\theta$ because you only need to use the potential function for $\vec F$ to prove the work done between two points is the difference in the potential function. Your derivation should be: 
Let $\vec F$ be conservative so that $\vec F = \nabla\phi(\vec r)= \left(\frac {\partial\phi(\vec r)}{\partial x},\frac {\partial\phi(\vec r)}{\partial y},\frac {\partial\phi(\vec r)}{\partial z}\right)$ 
The applied force does work against $\vec F$ and is therefore $-\vec F$, giving the work done by $-\vec F$ between $a$ and $b$ as $$\int^b_a-\vec F\cdot\vec{dr} =\int^b_a-\nabla\phi(\vec r) \cdot\vec{dr}= \phi (\vec a) - \phi (\vec b)$$
For a Coulomb electric field $\vec E = k \frac {q_1\vec r} {r^3}$, the corresponding $\phi(\vec r) = -k \frac {q_1q_2} {r}+$ const
Defining $\phi(\infty) = 0$ finally gives $$\int^b_\infty-k \frac {q_1q_2\vec r} {r^3}\cdot\vec{dr} = k \frac {q_1q_2} {b}$$
A: You're measuring the force between two point charges, and the force always acts along the line joining the charges. That means $cos(\theta)$ is always zero or $\pi$ i.e. $cos(\theta)$ is 1 or -1.
The equation for the force is not just the magnitude. The forces between two identical charges acts in a different direction to two opposite charges. You need to put $q$ into the equation with the correct sign and it will give you the force with the correct sign.
