0
$\begingroup$

How can we define a 3D function where for all input values of $(x, y, z)$ for $f(x,y,z) = 0$ or approximately close to zero except for where the location of a spherical shell is located.

The visualization of this is a beach ball. I want a function that describes the location of the beach ball material when blown up. I want the function to return zero or very close to zero inside the ball and outside the ball, but equal to $1$ or close to $1$ where the material is located.

Another way to say this is that I desire a 3D scalar field that yields the value of $1$ at a radius $r$ from the origin but yields zero for all other points that's not at such radius. Also, I eventually want to find the vector field from this scalar field and have arrows pointing normal to this "surface" that I hope we can define.

I know that the equation of a sphere is $x^2+y^2+z^2 = r^2$, but this isn't what I desire because you get a non-zero number everywhere!

I tried to use the Gaussian function to help me out, $\exp[-(x^2+y^2+z^2)]$, but this didn't work either. In the origin, $(0, 0, 0)$, the function equals $1$ and the farther you go out it goes to zero.

$\endgroup$
1
  • 3
    $\begingroup$ Why not $$f(x,y,z) = \begin{cases} 1 & x^2+y^2+z^2=r^2 \\ 0 & \text{else} \\ \end{cases}$$ $\endgroup$ Commented May 2, 2020 at 8:47

1 Answer 1

2
$\begingroup$

As Ninad Munshi suggests you obviously just want $$ f(x,y,z) = \begin{cases} 1, & x^2+y^2+z^2=r^2 \\ 0, & \text{else} \\ \end{cases} $$

If you want a smooth function you can take $f(x,y,z) = e^{-\lambda(x^2+y^2+z^2-r^2)^2}$ for some $\lambda>0.$ The larger $\lambda,$ the faster $f$ will drop off of the spherical shell.

$\endgroup$
2
  • $\begingroup$ Thank you so much. This is exactly what I was looking for! If I wanted to generalize this, would I put the function describing the shape inside the exponential? It looks like we put the sphere function inside the exponential. $\endgroup$ Commented May 2, 2020 at 16:23
  • $\begingroup$ If the surface is described by $g(x,y,z)=0$ then set $f(x,y,z) = e^{-\lambda g(x,y,z)^2}.$ $\endgroup$
    – md2perpe
    Commented May 2, 2020 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .