Combining Functions

© Mike Williams 2001,2002,2003,2004

Up | Previous: Variable Substitution | Next: Using Pigments as Functions | Alphabetical Index

Union


#declare  S = function {x*x + y*y +z*z - 1}
                     
isosurface {
  function { min(S(x+0.5,y,z), S(x-0.5,y,z)) }
        max_gradient 2
        contained_by{sphere{0,R}}
        pigment {rgb .9}
}
min() can be used to produce the union of two or more functions. In this case the union of two spheres, one translated -0.5 in the x direction and one translated +0.5 in the x direction.

Intersection


#declare  S = function {x*x + y*y +z*z - 1}
                     
isosurface {
  function { max(S(x+0.5,y,z),S(x-0.5,y,z)) }
        max_gradient 5
        contained_by{sphere{0,R}}
        pigment {rgb .9}
}
max() can be used to produce the intersection of two or more functions. In this case the same two spheres as above.

Addition and Subtraction


#include "functions.inc"

#declare  S = function {x*x + y*y + z*z - 1}

isosurface {
  function { S(x,y,z) + 
  f_noise3d(x*10, y*10, z*10)*0.3 }
        max_gradient 7
        contained_by{sphere{0,R}}
        pigment {rgb .9}
}

Adding two functions together produces a sort of blend between the two functions. A particular use of such a blend is to add one or more noise or noise-like functions to a surface.

In this case I've added a bit of f_noise3d to a sphere. The result of the addition is a surface with a generally spherical shape but with a noisy surface. I've used variable substitution to control the frequency of the noise.

Adding noise creates a surface that is slightly smaller than the original sphere - the noise pokes inwards from the surface. Subtracting noise creates a surface that is slightly larger than the original sphere - the noise stands slightly proud of the surface.

Blob-like combinations


#include "functions.inc"
#declare  S = function {f_sphere(x,y,z,0.5)}
#declare  T = function {f_torus(x,y,z,1,0.2)}

isosurface {
  function { S(x-0.7,y,z) * T(x,y,z) - 0.05}
        max_gradient 2
        accuracy 0.001
        contained_by{sphere{0,R}}
        pigment {rgb .9}
}

Multiplying surfaces then adding a small constant produces an effect that's similar to using blobs. However, this technique can be used to blob together any kind of isosurface, not just spheres and cylinders.


Download a zip file containing the POV source files for all the images that appear on this page.

Up | Previous: Variable Substitution | Next: Using Pigments as Functions | Alphabetical Index