# [Tex/LaTex] Intersection of two surfaces

intersectionspgfplots

I'm trying to create a signed distance function S(x), where I want to intersect S(x) = 0 with a plane. The problem is not to get the two functions into a plot, but to get the two functions to visual intersect with each other, i.e the nearest surface is in the foreground. Currently, I have something like:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=major]
{-sqrt((x-0)^2/1 + (y-0)^2/1) + 5};
{0*x+0*y};
\end{axis}
\end{tikzpicture}
\end{document}


Which gives:

As you can see, the plane is only overlapping the function and not intersecting. How can it be done? Bonus question: Is it possible to create a contour on the 3d surf plot at the intersection?

This can't be done automatically, unfortunately, since pgfplots can't do z buffering between different \addplot commands.

For this concrete application, you could construct the plot "by hand", however:

First, you draw the part of the cone below 0, then you draw the plane and the circle, then you draw the part of the cone above 0.

I've used a polar coordinate system for this, since it makes the input of polar functions easier:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=major,view={20}{40},z buffer=sort, data cs=polar]
\addplot3 [surf, domain=0:360, domain y=5:10,samples=30, samples y=10]
{-y+5};