TITLE: Looking for a 3D smooth step function
QUESTION [7 upvotes]: In 2D, I use $y=e^{\frac{-0.01}{1-|x|^2}}$ to model a step function and smooth the transition.
Anyone knows is there any good 3D step function and transiting smoothly. From $x-y$ plane, it should look like (1) A rectangular; (2) An elliptic.

REPLY [11 votes]: Practically, in 2D ideal step function is Heaviside step function. 
$$
\theta(x) = \left \{ \begin{array}{cc}
0, & x < 0 \\
\frac 12, & x = 0 \\
1, & x > 0
\end{array} \right .
$$

But in many cases for different purposes it needs to be smoothed out. Also, what people practically use as smooth approximation of it is Hyperbolic tangent function as
$$
\theta_\delta(x) = \frac 12 \left[1 + \tanh \left ( \frac x \delta \right ) \right ]
$$
where $\delta$ is a parameter that roughly controls the thickness of smooth transition zone.

But, sometimes there's a need to change support of the step function to make it more suitable for a particular problem. For example, a function that's significant at $x \in [a,b]$ and vanishes everywhere else. One can use Heaviside step function again, but combination of those now. 
$$
\theta_{[a,b]} = \theta(x-a)-\theta(x-b)
$$

Same trick can be done with smoothed version
$$
\theta_{\delta, [a,b]} = \theta_\delta(x-a)- \theta_\delta (x-b) = \frac 12 \left [ \tanh \left (\frac {x-a}\delta \right ) - \tanh \left (\frac {x-b}\delta \right )\right ]
$$

In 3D things are more complicated since

Dimension is higher
Support of the function may have some complex shape. 

So, let's say one wants to have a function with support $D$, i.e.
$$
\theta(\mathbf x) = \left \{ \begin{array}{cl}
1, & \mathbf x \in D \\
0, & \mathbf x \notin D
\end{array} \right .
$$
Another practical approach to smooth step function widely used here is via hyperbolic tangent function again but w.r.t. so called distance function. Namely
$$
\theta_\delta(\mathbf x) = \frac 12 \left \{ 1 + \tanh \left[ \frac {d(\mathbf x)} \delta \right ] \right \}
$$
Distance function $d(\mathbf x)$ here is a function that is closely related to the level set. It can be found as smallest of distances from a given point to the points from a given set. But main property of it is as follows
$$
d(x,y) = \left \{ \begin{array}{ll}
\text{negative}, & (x,y) \notin D \\
0, & (x,y) \in \delta D \\
\text{positive}, & (x, y) \in D
\end{array}\right .
$$
Finding that level set is a big problem itself and there are many methods to do that, mostly numerical, but as soon as it's done, one can immediately use it to find step function.
As an example, let's consider a circle
$$
D = \left \{ (x, y) \left |(x-a)^2 + (y-b)^2 = R^2 \right .\right \}
$$
as a support, because it's easy to find its distance function,
$$
d(x,y) = R - \sqrt{(x-a)^2+(y-b)^2}
$$
Smooth Step function is below.