I'm reading Stillwell's Mathematics and Its History. In the chapter about pythagorean triples, he says that we now know that the general formula for generating pythagorean triples is:
$$a = r\cdot(m^2 - n^2) ,\ \, b = r\cdot(2mn) ,\ \, c = r\cdot(m^2 + n^2)\tag{1}$$
And that there is a special case which gives all solutions $a,b,c$ without common divisor:
$$a = m^2 - n^2 ,\ \, b = 2mn ,\ \, c = m^2 + n^2\tag{2}$$
I'm just no so sure where are these formulas coming from. I've made the following trial: By looking $(2)$, I've written the formula for the pythagorean theorem and I've switched only the $c$:
$$a^2+b^2=\color{red}{(m^2 + n^2)^2}$$
And expanded it:
$$a^2+b^2=\color{red}{m^4+2n^2m^2+n^4}\tag{3}$$
Then my guess is that I should find arbitrary $a$, $b$ (and perhaps some integers?) written in terms of $n$ and $m$ such that $(3)$ is true. So I guess I need to split the polynomial in (perhaps) some arbitrary way such as:
$$a^2+b^2=\color{red}{m^4+2n^2m^2}\color{green}{+n^4}$$ $$a^2+b^2=\color{red}{m^4+n^2m^2}\color{green}{+n^2m^2+n^4}$$
And then find $a,b$ such that:
$$\begin{eqnarray*} {a^2}&=&{m^4+2n^2m^2} \\ {b^2}&=&{n^4} \end{eqnarray*}$$
Or:
$$\begin{eqnarray*} {a^2}&=&{m^4+n^2m^2} \\ {b^2}&=&{n^2m^2+n^4} \end{eqnarray*}$$
Or any arbitrary combination such that $(3)$ holds. I'm still a little stuck, am I on the right path? I've looked wikipedia article on pythagorean triples and there's no much insight into this matter.
If you read a few pages further you will find that Exercises 1.31. and 1.3.2 give a derivation of the Pythagorean triple formula using a rational parametrization of the circle (see also the "geometry" section of the Wikipedia article).
More generally, if a conic curve with rational coefficients has one rational point $\rm\:P\:$ then it has infinitely many, since any rational line through $\rm\:P\:$ will intersect the curve in another point, necessarily rational, since if one root of a rational quadratic is rational then so is the other. Therefore, by sweeping lines of varying rational slopes through $\rm\:P\:$ we obtain infinitely many rational points on the conic. Projecting these points onto a line leads to a rational parametrization of the conic. For a very nice exposition see Chapter $1$ of Silverman and Tate: Rational Points on Elliptic Curves. There are also many online expositions, e.g. search on "rational parametrization Pythagorean triple".
There are also many other ways to derive the formula. A particularly beautiful one-line way employs Hilbert's Theorem $90$ - see the award winning expository Monthly paper by Olga Taussky Sums of Squares.