# How do we derive the loop closure equations?

Looking to derive these equations. I don't intuitively understand what it means to take a cos of two independent angles added together. Nor do I understand why all of these are equal to 0. It is hard to visualize when all the angles seem independent.  I think perhaps you can proceed as follows:

1. First consider the each segment as a vector, $$\bar{r}_1$$, $$\bar{r}_2$$, etc.

2. The vectors each add as you place the tip of each to the tail of the following: $$\bar{r}$$ = $$\bar{r}_1$$ + $$\bar{r}_2$$ + $$\bar{r}_3$$ + $$\bar{r}_4$$

3. But you know that when you do this you just end up back at the origin - i.e.

$$\bar{r} = \bar{r}_1 + \bar{r}_2 + \bar{r}_3 + \bar{r}_4 = 0$$

1. This means that the $$x$$ and $$y$$ components must each add up to zero as well, since $$\bar{r}$$ = $$\hat{x}x$$ + $$\hat{y}y$$ $$= 0$$:

$$x = x_1 + x_2 + x_3 + x_4 = 0$$

$$y = y_1 + y_2 + y_3 + y_4 = 0$$

This is where the first two equations come from, with, e.g.:

$$x_1 = L_1\cos\theta_1$$ $$x_2 = L_2\cos(\theta_1+\theta_2)$$ $$\ldots$$

The last equation simply expresses the fact that you will end up back at the beginning as you rotate through each angle:

$$\theta_1 + \theta_2 + \theta_3 + \theta_4 = 2\pi$$

If some of the derivations are still a mystery, I recommend this paper from the MIT AI Lab. It is quite old but very clear.