# tikz 3d graph with circular domain

I have got a pretty simple function to make a 3D graph of. The function is defined as:

$f:D\rightarrow\mathbb{R},\quad f(\vec{x})=\left|\vec{x}-\begin{bmatrix}2\\5\end{bmatrix}\right|$

Plotting this was not that much of a problem with the follwing code:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{amsmath}
\begin{document}
\pgfplotsset{
compat=1.8,
colormap={whitered}{color(0cm)=(white); color(1cm)=(orange!75!red)}
}

\begin{tikzpicture}
\begin{axis}[
colormap name=whitered,
3d box,
width=15cm,
view={25}{25},
enlargelimits=false,
grid=major,
domain=-2:6,
y domain=1:9,
zmin=0,zmax=7,
samples=21,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
colorbar,
colorbar style={
at={(1,0)},
anchor=south west,
height=0.1*\pgfkeysvalueof{/pgfplots/parent axis height}
}
]
{sqrt((x-2)^2+(y-5)^2)};

\addplot3 [contour gnuplot = {number=14, labels={false},
draw color = black}, samples = 21, ]
{sqrt((x-2)^2+(y-5)^2)};

\addplot3 [contour gnuplot = {number=14, labels={false}, draw color=black},
samples=21,z filter/.code={\def\pgfmathresult{20}}]
{sqrt((x-2)^2+(y-5)^2)};
\end{axis}
\end{tikzpicture}
\end{document}


This produces the following output:

Now to my problem: My domain is defined circular as following:

$D:=\{(x,y)\in\mathbb{R}^2|(x-1)^2+y^2\leq9\}$

Is there any possibility limiting the plot to the given domain? Do I need to go for a completely different approach like another coordinate system than the Cartesian or something like that?

Partial solution (I skipped the contour level plots to simplify, let that as an exercise for the braves):

Using the three-way if (boolean)?(value if true):(value if false) and the special "number" NaN (not-a-number), and using the option unbounded coords=jump you can do the following:

\addplot3 [surf, unbounded coords=jump]
{ (x-2)^2+(y-5)^2<9 ? sqrt((x-2)^2+(y-5)^2) : NaN };


You have

with your bound -- (x-1)^2+y^2<9 (which is not centered with respect to the center of the ellipsoid) it is a bit strange:

...but I think it's ok note it changed the x and y scales, if you fix them:

• That NaN was what I was looking for thank you so much :) – Nik-Sch May 4 '16 at 8:30
• Notice that unbounded coords=jump is necessary here --- otherwise strange things will happen. – Rmano May 4 '16 at 8:31
• Oh ok. Good to know. Currently I am at University but as soon as I get home I will try it – Nik-Sch May 4 '16 at 8:32