1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
<!-- This file copyright Persistence of Vision Raytracer Pty. Ltd. 2003-2004 -->
<html>
<head>
<!-- NOTE: In order to users to help find information about POV-Ray using -->
<!-- web search engines, we ask you to *not* let them index documentation -->
<!-- mirrors because effectively, when searching, users will get hundreds -->
<!-- of results containing the same information! For this reason, the two -->
<!-- meta tags below disable archiving and indexing of this page by all -->
<!-- search engines that support these meta tags. -->
<meta content="noarchive" name="robots">
<meta content="noindex" name="robots">
<meta content="no-cache" http-equiv="Pragma">
<meta content="0" http-equiv="expires">
<title>3.4.6 Constructive Solid Geometry</title>
<link href="povray35.css" rel="stylesheet" type="text/css">
</head>
<body>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_109.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_109.html">3.4.5 Parametric Object</a>
</td>
<td align="center" valign="middle">
<strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>3.4.6
Constructive Solid Geometry</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_111.html">3.4.7 Light Sources</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_111.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
<h3><a name="s03_04_06">3.4.6 </a>Constructive Solid Geometry</h3>
<a name="s03_04_06_i1"><a name="CSG"></a>
<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: union,
intersection, difference, and merge. CSG objects can be composed of primitives or other CSG objects to create more,
and more complex shapes.
</p>
<h4><a name="s03_04_06_01">3.4.6.1 </a>Inside and Outside</h4>
<p>
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.
</p>
<p>
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 (<code>mesh, 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 triangles, bicubic_patches 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.
</p>
<p>
CSG uses the concepts of inside and outside to combine shapes together as explained in the following sections.
</p>
<p>
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 <code>A</code> nor in object <code>B</code>, points that are
in object <code>A</code> but not in object <code>B</code>, points that are not in object <code>A</code> but in object <code>B</code>
and last not least points that are in object <code> A</code> and object <code>B</code>.
</p>
<p>
<br><center><img alt="Two overlapping objects." src="images/reference/objoverl.png"></center>
</p>
<p>
Keeping this in mind it will be quite easy to understand how the CSG operations work.
</p>
<p>
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 <code>inverse</code> keyword is used the <em> inside</em>
of the shape is flipped to become the <em> outside</em> and vice versa.
</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 "Finite Patch Primitives" have no well defined inside/outside. All objects described in the
sections "Finite Solid Primitives" and "Infinite Solid Primitives".
</p>
<h4><a name="s03_04_06_02">3.4.6.2 </a>Union</h4>
<a name="s03_04_06_02_i1"><a name="s03_04_06_02_i2"><a name="union"></a><a name="s03_04_06_02_i3"><a name="union, keyword"></a><a name="s03_04_06_02_i4">
<p>
<br><center><img alt="The union of two objects." src="images/reference/unionobj.png"></center>
</p>
<p>
The simplest kind of CSG is the <code>union</code>. The syntax is:
</p>
<pre>
UNION:
union
{
OBJECTS...
[OBJECT_MODIFIERS...]
}
</pre>
<p>
Unions are simply glue used to bind two or more shapes into a single entity that can be manipulated as a single
object. The image above shows the union of <code>A</code> and <code>B</code>. The new object created by the union
operation can be scaled, translated and rotated as a single shape. The entire union can share a single texture but
each object contained in the union may also have its own texture, which will override any texture statements in the
parent object.
</p>
<p>
You should be aware that the surfaces inside the union will not be removed. As you can see from the figure this may
be a problem for transparent unions. If you want those surfaces to be removed you will have to use the <code> merge</code>
operations explained in a later section.
</p>
<p>
The following union will contain a box and a sphere.
</p>
<pre>
union {
box { <-1.5, -1, -1>, <0.5, 1, 1> }
cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 }
}
</pre>
<a name="s03_04_06_02_i5"><a name="composite"></a>
<p>
Earlier versions of POV-Ray placed restrictions on unions so you often had to combine objects with <code>composite</code>
statements. Those earlier restrictions have been lifted so <code>composite</code> is no longer needed. It is still
supported for backwards compatibility.
</p>
<h5><a name="s03_04_06_02_01">3.4.6.2.1 </a>Split_Union</h5>
<a name="s03_04_06_02_01_i1"><a name="split_union, union"></a><a name="s03_04_06_02_01_i2">
<p>
<code>split_union</code> is a boolean keyword that can be added to a union. It has two states <code>on</code>/<code>off</code>,
its default is <code>on</code>.
</p>
<p>
<code>split_union</code> is used when <a href="s_130.html#s03_06_03_02_02">photons</a> are shot at the CSG-object.
The object is split up in its compound parts, photons are shot at each part separately. This is to prevent photons
from being shot at 'empty spaces' in the object, for example the holes in a grid. With compact objects, without 'empty
spaces' <code>split_union off</code> can improve photon gathering.
</p>
<pre>
union {
object {...}
object {...}
split_union off
}
</pre>
<h4><a name="s03_04_06_03">3.4.6.3 </a>Intersection</h4>
<a name="s03_04_06_03_i1"><a name="s03_04_06_03_i2"><a name="intersection"></a><a name="s03_04_06_03_i3"><a name="intersection, keyword"></a><a name="s03_04_06_03_i4">
<p>
The <code>intersection</code> object creates a shape containing only those areas where all components overlap. A
point is part of an intersection if it is inside both objects, <code>A</code> and <code>B</code>, as show in the
figure below.
</p>
<p>
<br><center><img alt="The intersection of two objects." src="images/reference/isectobj.png"></center>
</p>
<p>
The syntax is:
</p>
<pre>
INTERSECTION:
intersection
{
SOLID_OBJECTS...
[OBJECT_MODIFIERS...]
}
</pre>
<p>
The component objects must have well defined inside/outside properties. Patch objects are not allowed.
</p>
<p class="Note">
<strong>Note:</strong> if all components do not overlap, the intersection object disappears.
</p>
<p>
Here is an example that overlaps:
</p>
<pre>
intersection {
box { <-1.5, -1, -1>, <0.5, 1, 1> }
cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 }
}
</pre>
<h4><a name="s03_04_06_04">3.4.6.4 </a>Difference</h4>
<a name="s03_04_06_04_i1"><a name="s03_04_06_04_i2"><a name="difference"></a><a name="s03_04_06_04_i3"><a name="difference, keyword"></a><a name="s03_04_06_04_i4">
<p>
The CSG <code>difference</code> operation takes the intersection between the first object and the inverse of all
subsequent objects. Thus only points inside object <code>A</code> and outside object <code>B</code> belong to the
difference of both objects.
</p>
<p>
The result is a subtraction of the 2nd shape from the first shape as shown in the figure below.
</p>
<p>
<br><center><img alt="The difference between two objects." src="images/reference/diffobj.png"></center>
</p>
<p>
The syntax is:
</p>
<pre>
DIFFERENCE:
difference
{
SOLID_OBJECTS...
[OBJECT_MODIFIERS...]
}
</pre>
<p>
The component objects must have well defined inside/outside properties. Patch objects are not allowed.
</p>
<p class="Note">
<strong>Note:</strong> if the first object is entirely inside the subtracted objects, the difference
object disappears.
</p>
<p>
Here is an example of a properly formed difference:
</p>
<pre>
difference {
box { <-1.5, -1, -1>, <0.5, 1, 1> }
cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 }
}
</pre>
<p class="Note">
<strong>Note:</strong> internally, POV-Ray simply adds the <code>inverse</code> keyword to the second
(and subsequent) objects and then performs an intersection.
</p>
<p>
The example above is equivalent to:
</p>
<pre>
intersection {
box { <-1.5, -1, -1>, <0.5, 1, 1> }
cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 inverse }
}
</pre>
<h4><a name="s03_04_06_05">3.4.6.5 </a>Merge</h4>
<a name="s03_04_06_05_i1"><a name="s03_04_06_05_i2"><a name="merge"></a><a name="s03_04_06_05_i3"><a name="merge, keyword"></a><a name="s03_04_06_05_i4">
<p>
The <code>union</code> operation just glues objects together, it does not remove the objects' surfaces inside the <code>union</code>.
Under most circumstances this does not matter. However if a transparent <code> union</code> is used, those interior
surfaces will be visible. The <code> merge</code> operations can be used to avoid this problem. It works just like <code>union</code>
but it eliminates the inner surfaces like shown in the figure below.
</p>
<p>
<br><center><img alt="Merge removes inner surfaces." src="images/reference/mergeobj.png"></center>
</p>
<p>
The syntax is:
</p>
<pre>
MERGE:
merge
{
SOLID_OBJECTS...
[OBJECT_MODIFIERS...]
}
</pre>
<p>
The component objects must have well defined inside/outside properties. Patch objects are not allowed.
</p>
<p class="Note">
<strong>Note:</strong> that in general <code>merge</code> is slower rendering than <code>union</code>
when used with non transparent objects. A small test may be needed to determine what is the optimal solution regarding
speed and visual result.
</p>
<br>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_109.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_109.html">3.4.5 Parametric Object</a>
</td>
<td align="center" valign="middle">
<strong>3.4.6 Constructive Solid Geometry</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_111.html">3.4.7 Light Sources</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_111.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
</body> </html>
|