Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    CSG - Constructive Solid Geometry - b
Italiano Italiano
Français français
Deutsch Deutsch

Home
- POV-Ray Tutorial
- Download-Page

  - CSG Constructive
            Solid
            Geometry
    - union + merge
   > difference
    - intersection
       + invers
    - clipped_by
    - coincident surfaces
    - textures in CSG
                                           
Boolean Algebra with solids - part III

About "difference"



difference{...}

With the "difference" statement you can subtract from a basic object all subsequent objects from the first one. With this statement it is possible to drill out holes and shape out any kind of notches or beveling you want. This statement is like a milling machine the used milling head has the shape of the objects which are following the base object. The "hole" gets the texture from the subtracted object. That's the theory.
The following insidious trap - not only for beginners - is a pitfall which produces many frustrations:
This is the problem of the "coincident surfaces". If the object to subtract does not has surfaces which are not unambigious outside the object from which to subtract, then the program is not able to decide wether a point of this surface is subtracted or not. And most times some strange colored speckles appear where the hole is supposed to be. This is no error of the program. This effect has his origine in numerical problems because of inavoidable rounding by computers.
Therefore it is essential to avoid coincident surfaces!
(See also: "Coincident Surface Problems")

The Defect:
difference{
box {<-0.5,0.0,-0.1>,< 0.5,1.0,0.1>
     texture{ pigment{ color rgb<1,0.65,0>}
              finish { phong 1.0 }}
    }
box {<-0.3,0.2,-0.1>,< 0.3,0.8,0.1>
     texture{ pigment{ color Magenta}
              finish { phong 1.0 }}
    }
rotate<0,-30,0> translate<0,0,0>}
The Solution:
#declare D = 0.001; // just a little bit!
difference{
box{ <-0.5,0.0,-0.1>,< 0.5,1.0,0.1>
     texture{ pigment{ color rgb<1,0.65,0>}
              finish { phong 1.0 }}
   }
box{ <-0.3,0.2,-0.1-D>,< 0.3,0.8,0.1+D>
     texture{ pigment{ color Magenta }
              finish { phong 1.0 }}
   }
rotate<0,-30,0> translate<0,0,0>}


CSG | union + merge | difference | intersection + inverse | clipped_by | coincident surfaces | textures
top

© Friedrich A. Lohmüller, 2012
www.f-lohmueller.de