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.