(* +-X Patch *)
nu[x_,z_]:=ArcTan[z/x]
ph[x_,y_]:=ArcTan[y/x]

x[r_, nu_,ph_]:=r/Sqrt[1+Tan[nu]^2+Tan[ph]^2]
y[r_, nu_,ph_]:=x[r, nu,ph]*Tan[ph]
z[r_, nu_,ph_]:=x[r, nu,ph]*Tan[nu]

(* +-Y Patch *)
mu[y_,z_]:=ArcTan[z/y]
ph[x_,y_]:=ArcTan[x/y]

y[r_, mu_,ph_]:=r/Sqrt[1+Tan[mu]^2+Tan[ph]^2]
x[r_, mu_,ph_]:=y[r, mu,ph]*Tan[ph]
z[r_, mu_,ph_]:=y[r, mu,ph]*Tan[mu]

(* +- Z Patch *)
mu[y_,z_]:=ArcTan[y/z]
nu[x_,z_]:=ArcTan[x/z]

z[r_, mu_,nu_]:=r/Sqrt[1+Tan[mu]^2+Tan[nu]^2]
x[r_, mu_,nu_]:=z[r, mu,nu]*Tan[nu]
y[r_, mu_,nu_]:=z[r, mu,nu]*Tan[mu]

(* Spherical coordinates *)
r[x_,y_,z_]:=Sqrt[x^2+y^2+z^2]
theta[z_,r_]:=ArcCos[z/r]
phi[x_,y_]:=ArcTan[y/x]
(*rho:=+Pi/4*)
(*sigma:=0*)
th[rho_,sigma_]:=Simplify[theta[z[r, rho,sigma], r]]
ph[rho_,sigma_]:=Simplify[phi[x[r, rho,sigma],y[r, rho,sigma]]]

th[rho, sigma]
ph[rho, sigma]
th[-Pi/4, 0]
ph[0, -Pi/4]
th[0, 0]
ph[0, 0]

(* Line-element for constant radius *)
ds[rho_, sigma_]:=(*MatrixForm[*){{Simplify[(D[ph[rho,sigma],rho])^2*Sin[th[rho,sigma]]^2+(D[th[rho,sigma], rho])^2], Simplify[D[ph[rho,sigma],rho]*D[ph[rho,sigma], sigma]*Sin[th[rho,sigma]]^2+D[th[rho,sigma], rho]*D[th[rho,sigma], sigma]]},{ Simplify[D[ph[rho,sigma],rho]*D[ph[rho,sigma], sigma]*Sin[th[rho,sigma]]^2+D[th[rho,sigma], rho]*D[th[rho,sigma], sigma]],Simplify[D[ph[rho,sigma], sigma]^2*Sin[th[rho,sigma]]^2+D[th[rho,sigma], sigma]^2]}}(*]*)

(*Simplify[r*(D[ph[rho,sigma],rho]*droh+D[ph[rho,sigma], sigma]*dsigma)^2+r*(D[th[rho,sigma], rho]*droh+D[th[rho,sigma], sigma]*dsigma)^2]*)

(* Determinant *)
Simplify[Sqrt[Det[ds[rho,sigma]]]]

(* Line element for non-constant radius *)
dx2=(D[x[r[rho,sigma], rho, sigma], rho]*drho + D[x[r[rho,sigma], rho, sigma], sigma]*dsigma  + D[x[r[rho,sigma], rho, sigma], r]*dr )^2

dy2=(D[y[r[rho,sigma], rho, sigma], rho]*drho + D[y[r[rho,sigma], rho, sigma], sigma]*dsigma  + D[y[r[rho,sigma], rho, sigma], r]*dr )^2

dz2=(D[z[r[rho,sigma], rho, sigma], rho]*drho + D[z[r[rho,sigma], rho, sigma], sigma]*dsigma  + D[z[r[rho,sigma], rho, sigma], r]*dr )^2

ds2:=Simplify[dx2+dy2+dz2]
g11=Expand[ds2]//.{drho^2->1, dsigma->0}
g12=Expand[ds2]//.{drho*dsigma->1, drho^2->0, dsigma^2->0}
g22=Expand[ds2]//.{dsigma^2->1, drho->0}

det:=Simplify[Sqrt[g11*g22-1/4*g12^2]]
det=det//.{r[rho,sigma]-> r, Derivative[0,1][r][rho,sigma]->drdsigma,Derivative[1,0][r][rho,sigma]->drdrho}

<<"Format.m"
CAssign[mydet, det, AssignOptimize->False]