How to study the work done by a varying force on a system moving in two dimensions? My book states that:

$$W=\int_{x_i}^{x_f}{F_x dx}$$

We can calculate the area under the curve representing force as a function of position when the displacement and the force are in one direction since $\cos \theta = 1$ using the integral provided; but, what if we have different cases where the force varies?
What if the force and displacement were not in the same direction($\cos \theta \neq 1$)?
What if $\theta = 0$, but the motion was in two dimensions as a particle moving in a circular path?
 A: In general you should consider the expression
$$
W = \int_\gamma {\bf F}\cdot {\rm d}{\bf x}
$$
where $\gamma$ is a path, ${\bf F}$ is the force and ${\rm d}{\bf x}$ is a tangent element to the path. To give you an example, imagine the particle is moving along a circle of radius $R$, you can parametrize the path as $\gamma = \{(x, y) | x = R\cos t,~~ y = R\sin t\}$, so the tangent element is ${\rm d}{\bf x} = R {\rm d}t~\hat{u}$, where $\hat{u} = (-\sin t, \cos t)$. You just need to calculate the dot product with the force and integrate
A: You can write :
$W=\int_{\mathbf{r}_i}^{\mathbf{r}_f}\mathbf{F}(\mathbf{r})d\mathbf{r}=\int_0^S F(s)\cos(\theta(s))ds$ where $s$ is the length of the path.
If $\cos(\theta)$ is constant, you can take it out from the integral. If you're on a circle and you pull towards the center (a bit like the Sun on the earth if the orbit was a circle), the work is zero.
On a circular path, if $\cos \theta= 1$, it's like if you were in one dimension, but you have to pay attention to the fact that you're not going from 0 to 0 but from 0 to $\alpha r$, with $\alpha$ the angle that you did around the center.
PS: you can play with the time also 
$W=\int_{\mathbf{r}(t_i)}^{\mathbf{r}(t_f)}\mathbf{F}(t)d\mathbf{r}(t)=\int_{t_i}^{t_f}\mathbf{F}(t)\mathbf{v}(t)dt=\int_{t_i}^{t_f}F(t)v(t)\cos(\theta(t))dt$
