# formula for inverse multidimensional stereographic projection

i'm in need of formula for inverse multidimensional stereographic projection with variant radius of the sphere. Sadly the only ones i'm able to find have either fixed number of dimensions or don't support variable radius.

Using Cartesian coordinates $X_1,\dots ,X_n$ in Euclidean $n$-space and $x_1,\dots,x_{n+1}$ on the space in which the sphere $x_1^2+\dots +x_{n+1}^2=R^2$ lives, we have: $$X_k=\frac{x_kR}{R-x_{n+1}},\quad k=1,\dots,n \tag1$$ and in the converse direction, $$x_k=\frac{2RX_k}{|X|^2+R^2},\quad k=1,\dots,n;\qquad x_{n+1}=\frac{|X|^2-R^2}{|X|^2+R^2} \tag2$$ where $|X|^2=\sum_{j=1}^n X_j^2$.