Difference between revisions of "Reference:Constructive Solid Geometry"

From POV-Wiki
Jump to navigation Jump to search
m (cleanup round 2)
 
m (link addition)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
{{#indexentry:CSG}}
 
{{#indexentry:CSG}}
<p>In addition to all of the primitive shapes POV-Ray supports, you can also combine multiple simple shapes into complex shapes using <em> Constructive Solid Geometry</em> (CSG). There are four basic types of CSG operations: [[Reference:Union|union]], [[Reference:Intersection|intersection]], [[Reference:Difference|difference]], and [[Reference:Merge|merge]]. CSG objects can be composed of primitives or other CSG objects to create more, and more complex shapes.</p>
+
<p>In addition to all of the primitive shapes POV-Ray supports, you can also combine multiple simple shapes into complex shapes using <em> Constructive Solid Geometry</em> (CSG). There are four basic types of CSG operations: [[Reference:Union|union]], [[Reference:Intersection|intersection]], [[Reference:Difference|difference]], and [[Reference:Merge|merge]]. CSG objects can be composed of primitives or other CSG objects to create more, and more complex shapes. See also: [[Reference:Object Modifiers|Object Modifiers]].</p>
  
 
===Inside and Outside===
 
===Inside and Outside===
Line 12: Line 12:
 
of the plane points towards the outside of the plane. You should note that
 
of the plane points towards the outside of the plane. You should note that
 
triangles cannot be used as solid objects in CSG since they have no well defined inside and outside. Triangle-based shapes (<code>mesh</code> and <code>mesh2</code>) can only be used in CSG when they are closed objects and have an inside vector specified. </p>
 
triangles cannot be used as solid objects in CSG since they have no well defined inside and outside. Triangle-based shapes (<code>mesh</code> and <code>mesh2</code>) can only be used in CSG when they are closed objects and have an inside vector specified. </p>
<p class="Note"><strong>Note:</strong> Although the <code>triangle</code>, the <code>bicubic_patch</code> and some other shapes have no well defined inside and outside, they have a front- and backside which makes it possible to use a texture on the front side and an <code>interior_texture</code> on the back side.</p>
+
<p class="Note"><strong>Note:</strong> Although the <code>triangle</code>, the <code>bicubic_patch</code> and some other shapes have no well defined inside and outside, they have a front and backside which makes it possible to use a texture on the front side and an <code>interior_texture</code> on the back side.</p>
 
<p>
 
<p>
 
CSG uses the concepts of inside and outside to combine shapes together as
 
CSG uses the concepts of inside and outside to combine shapes together as
Line 47: Line 47:
 
versa.</p>
 
versa.</p>
 
<p>
 
<p>
The inside/outside distinction is not important for a <code>union</code>, but is important for <code>intersection</code>, <code>difference</code>, and <code>merge</code>. Therefore any objects may be combined using <code>union</code> but only solid objects, i.e. objects that have a well-defined interior can be used in the other kinds of CSG. The objects described in
+
The inside / outside distinction is not important for a <code>union</code>, but is important for <code>intersection</code>, <code>difference</code>, and <code>merge</code>. Therefore any objects may be combined using <code>union</code> but only solid objects, i.e. objects that have a well-defined interior can be used in the other kinds of CSG. The objects described in
[[Reference:Finite Patch Primitives|Finite Patch Primitives]] have no well defined inside/outside. All objects described in the sections [[Reference:Finite Solid Primitives|Finite Solid Primitives]] and [[Reference:Infinite Solid Primitives|Infinite Solid Primitives]].</p>
+
[[Reference:Finite Patch Primitives|Finite Patch Primitives]] have no well defined inside / outside, while the objects described in the sections [[Reference:Finite Solid Primitives|Finite Solid Primitives]] and [[Reference:Infinite Solid Primitives|Infinite Solid Primitives]] do.</p>

Latest revision as of 12:23, 27 March 2020

In addition to all of the primitive shapes POV-Ray supports, you can also combine multiple simple shapes into complex shapes using Constructive Solid Geometry (CSG). There are four basic types of CSG operations: union, intersection, difference, and merge. CSG objects can be composed of primitives or other CSG objects to create more, and more complex shapes. See also: Object Modifiers.

Inside and Outside

Most shape primitives, like spheres, boxes and blobs divide the world into two regions. One region is inside the object and one is outside. Given any point in space you can say it is either inside or outside any particular primitive object. Well, it could be exactly on the surface but this case is rather hard to determine due to numerical problems.

Even planes have an inside and an outside. By definition, the surface normal of the plane points towards the outside of the plane. You should note that triangles cannot be used as solid objects in CSG since they have no well defined inside and outside. Triangle-based shapes (mesh and mesh2) can only be used in CSG when they are closed objects and have an inside vector specified.

Note: Although the triangle, the bicubic_patch and some other shapes have no well defined inside and outside, they have a front and backside which makes it possible to use a texture on the front side and an interior_texture on the back side.

CSG uses the concepts of inside and outside to combine shapes together as explained in the following sections.

Imagine you have two objects that partially overlap like shown in the figure below. Four different areas of points can be distinguished: points that are neither in object A nor in object B, points that are in object A but not in object B, points that are not in object A but in object B and last not least points that are in object A and object B.

RefImgObjoverl.gif

Two overlapping objects.

Keeping this in mind it will be quite easy to understand how the CSG operations work.

When using CSG it is often useful to invert an object so that it will be inside-out. The appearance of the object is not changed, just the way that POV-Ray perceives it. When the inverse keyword is used the inside of the shape is flipped to become the outside and vice versa.

The inside / outside distinction is not important for a union, but is important for intersection, difference, and merge. Therefore any objects may be combined using union but only solid objects, i.e. objects that have a well-defined interior can be used in the other kinds of CSG. The objects described in Finite Patch Primitives have no well defined inside / outside, while the objects described in the sections Finite Solid Primitives and Infinite Solid Primitives do.