1
$\begingroup$

I have a number of functions that define 3d shapes. They take a point $(x, y, z)$ as a parameter and return a real value representing information about the shape.

  • On the surface of the shape: $f(x) = 0$
  • Inside the shape: $f(x) > 0$
  • Outside the shape: $f(x) < 0$

I have the function of a sphere defined as: $$s(x, y, z) = r^2 - ((x - x_c)^2+(y - y_c)^2+(z - z_c)^2)$$ where $(x_c, y_c, z_c)$ is defined as the center of the sphere, and $r$ as its radius.

I then have a function that defines a cube: $$c(x, y, z) = L/2 - \max(|x - x_c|, |y - y_c|, |z-z_c|)$$ Again, where $(x_c, y_c, z_c)$ is defined as the center of the cube, and $L$ is its side length.

Finally I have a function which can subtract the second shape from the first defined as: $$d(c(x, y, z), s(x, y, z)) = \min(c(x, y, z), -s(x, y, z))$$

Now, for example I have a sphere with a radius of $1$ centered at $(0, 1, 0)$ (the $y$ position is considered up in 3d space for this example), and a cube of side length $1$ centered at $(0, 0, 0)$. If I then subtract the sphere from the cube I'm left with something that looks like the following:

example

You can actually play with this example in your browser (Chrome or Firefox) by clicking here

What I would like to know is if there are some generic techniques for determining some properties of the resultant shape. Such as:

  • Surface Area
  • Volume
  • Axis aligned bounding cube

Apologies for the extremely long setup, I'd appreciate any discussion or help.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.