Formula to display a $3D$ $90$ degree pipe bend I am trying to display a $3D$ Pipe with $90°$ bend. I am writing code for it, but I am sure this is more of a mathematical question as a programming one. 
It would be nice if anyone could help me with the formula of displaying this bend. The $90°$ bend is basically the top left quarter of a circle.
 A: If you put 4 of these pieces together you would get a torus. So you just need to consider a parametric equation for a torus but restrict to a subset of the domain of the parameters. If you want the radius of the cross section of the pipe to be $a$, and the distance from the center of the bend of the pipe to the center of one of the cross sectional circles to be $c$, then a parametric representation is given by (in radians)
$$\begin{array}{rcl}
x & = & (c+a\cos v)\cos u \\
y & = & (c+a\cos v)\sin u\\
z & = & a\sin v
\end{array}$$
where $v\in [0,2\pi)$ and $u\in [0,\pi/2]$ (in degree this would be $v\in [0,360)$ and $u\in [0,90]$). If you let $u$ run over some different range then you will get different lengthed 'segments' of the torus, so for instance if $u$ was allowed to run through $[0,\pi]$ then you would sweep out a full half torus, or a 180 degree bend.
A: A circle in 3D is called a torus in mathematics. For a torus, which lies in the x-y-plane and is centered at the origin, all points belonging to the torus are described by the equation
$$\left(R - \sqrt{x^2 + y^2}\right)^2 + z^2 = r^2,$$
where $R$ is the "major" radius of the torus and $r$ is the radius of the "pipe". If you only want the upper left quarter of the torus, then you have to restrict the solutions to $x\leq 0$ and $y\geq 0$.
But I guess if you have some kind of software to draw the pipe, it won't be able to find all the solutions for you. So you probably have to compute some solutions numerically and then draw a polygon or something like this. If you tell me, what kind of input your software needs, I might be able to give you some more hints.
