Pythagorean Quadruples and Stereographic Projection I am trying to solve Diophantine equation $a^2+b^2+c^2=d^2$ by transforming this equation, assuming $d \neq 0$, into a sphere $ (\frac{a}{d})^2 + (\frac{b}{d})^2 +(\frac{c}{d})^2 = x^2 + y^2 +z^2 =1$ and using stereographic projection of this sphere from $N = (0,0,1)$ onto $ {x,y}$ plane. 
Each point $P^{'}=(x_{0},y_{0},0)$ from $x,y$ plane is a projection of a point $P=(x,y,z)$ on the sphere, where $x=\frac{2x_{0}}{1+x_{0}^2+y_{0}^2}$, $y=\frac{2y_{0}}{1+x_{0}^2+y_{0}^2}$ and $z=\frac{x_{0}^2+y_{0}^2-1}{1+x_{0}^2+y_{0}^2}$. Using $P^{'} \in \mathbb{Q^2} \iff P \in \mathbb{Q^3}$ we know that for each rational point from the plane we can obtain a solution. Therefore for $x_{0}=\frac{m}{n}$ and $y_{0}=\frac{p}{q}$ such that $m,n,p,q \in \mathbb{N}$ and $GCD(m,n)=GCD(p,q)=1$ we get $$x=\frac{m^2q^2+p^2n^2-n^2q^2}{n^2p^2+m^2q^2+n^2q^2}, y=\frac{2mnq^2}{n^2p^2+m^2q^2+n^2q^2}, z=\frac{2pn^2q}{n^2p^2+m^2q^2+n^2q^2}$$
Then multiplying by $n^2p^2+m^2q^2+n^2q^2$: $$a=m^2q^2+p^2n^2-n^2q^2, b=2mnq^2, c=2pn^2q, d=n^2p^2+m^2q^2+n^2q^2$$
I want to find all primitive quadruples, so $GCD(a,b,c,d)$ must be equal to one, however, at this point I am not sure how to continue. I've tried to compute $GCD(2pn^2q,2mnq^2)=2nq \ GCD(pn,mq)$, unsuccessfully. 

You are on the right track; indeed you have $\gcd(b,c)=2nq\gcd(np,mq)$, and also
$$\gcd(a,d)=\gcd(d,d-a)=\gcd(n^2p^2+m^2q^2+n^2q^2,2n^2q^2),$$
which shows that $\gcd(a,b,c,d)$ divides $2n^2q^2$. It follows that
\begin{eqnarray*}
\gcd(a,b,c,d)&=&\gcd(d,d-a,\gcd(b,c))=\gcd(d,2n^2q^2,2nq\gcd(np,mq)),
\end{eqnarray*}
where in turn
$$\gcd(2n^2q^2,2nq\gcd(np,mq)),=2nq\gcd(nq,\gcd(np,mq))=2nq\gcd(nq,np,mq).$$
By assumption $\gcd(m,n)=\gcd(p,q)=1$ and so
$$\gcd(nq,np,mq)=\gcd(n,mq)=\gcd(n,q),$$
which means that
$$\gcd(a,b,c,d)=\gcd(d,2nq\gcd(n,q))=\gcd(n^2p^2+m^2q^2,2nq\gcd(n,q)).$$
Now if $r$ is an odd prime dividing $\gcd(a,b,c,d)$ then it divides $2nq\gcd(n,q)$ and hence it divides either $n$ or $q$, or both. If $r$ divides only $n$, then it does not divide $n^2p^2+m^2q^2$ a contradiction. Similarly, if $r$ divides only $q$ then it does not divides $n^2p^2+m^2q^2$, a contradiction. This shows that the odd prime factors of $\gcd(a,b,c,d)$ divide both $n$ and $q$, and hence $\gcd(n,q)$.
If $\gcd(a,b,c,d)$ is even then $n^2p^2+m^2q^2$ is even, meaning that either $n$ and $q$ are even, or $m$ and $p$ are even.
It is clear that $\gcd(n,q)$ divides $a$, $b$, $c$ and $d$ and therefore also $\gcd(a,b,c,d)$. It follows that $\gcd(a,b,c,d)=1$ if and only if $\gcd(n,q)=1$ and $2\nmid\gcd(m,p)$.
