| 12
 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
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 
 | 
<!--  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.2 Finite Patch Primitives</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_105.html"><img alt="previous" border="0" src="prev.png"></a> 
   
  </td>
   
  <td align="left" valign="middle" width="30%">
    <a href="s_105.html">3.4.1 Finite Solid Primitives</a> 
  </td>
   
  <td align="center" valign="middle">
    <strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>3.4.2 
   Finite Patch Primitives</strong> 
  </td>
   
  <td align="right" valign="middle" width="30%">
    <a href="s_107.html">3.4.3 Infinite Solid Primitives</a> 
  </td>
   
  <td align="right" nowrap="" valign="middle" width="32">
    <a href="s_107.html"><img alt="next" border="0" src="next.png"></a> 
   
  </td>
   
 </tr>
  
</table>
 
<h3><a name="s03_04_02">3.4.2 </a>Finite Patch Primitives</h3>
<p>
  There are six totally thin, finite objects which have no well-defined inside. They are bicubic patch, disc, smooth 
 triangle, triangle, polygon and mesh / mesh2. They may be combined in CSG union but cannot be used in other types of 
 CSG (or inside a <code>clipped_by</code> statement). Because these types are finite POV-Ray can use automatic bounding 
 on them to speed up rendering time. As with all shapes they can be translated, rotated and scaled. 
</p>
<h4><a name="s03_04_02_01">3.4.2.1 </a>Bicubic Patch</h4>
<a name="s03_04_02_01_i1"><a name="bezier"></a><a name="s03_04_02_01_i2"><a name="s03_04_02_01_i3"><a name="bicubic_patch"></a><a name="s03_04_02_01_i4"><a name="bicubic_patch, keyword"></a><a name="s03_04_02_01_i5"><a name="s03_04_02_01_i6"><a name="type, bicubic_patch"></a><a name="s03_04_02_01_i7"><a name="s03_04_02_01_i8"><a name="u_steps, bicubic_patch"></a><a name="s03_04_02_01_i9"><a name="s03_04_02_01_i10"><a name="v_steps, bicubic_patch"></a><a name="s03_04_02_01_i11"><a name="s03_04_02_01_i12"><a name="flatness, bicubic_patch"></a><a name="s03_04_02_01_i13">
<p>
  A <code>bicubic_patch</code> is a 3D curved surface created from a mesh of triangles. POV-Ray supports a type of 
 bicubic patch called a <em>Bezier patch</em>. A bicubic patch is defined as follows: 
</p>
<pre>
BICUBIC_PATCH:
    bicubic_patch
    {
        PATCH_ITEMS...
        <Point_1>,<Point_2>,<Point_3>,<Point_4>,
        <Point_5>,<Point_6>,<Point_7>,<Point_8>,
        <Point_9>,<Point_10>,<Point_11>,<Point_12>,
        <Point_13>,<Point_14>,<Point_15>,<Point_16>
        [OBJECT_MODIFIERS...]
    }
PATCH_ITEMS:
    type Patch_Type | u_steps Num_U_Steps | v_steps Num_V_Steps |
    flatness Flatness
</pre>
<p>
  Bicubic patch default values: <a name="s03_04_02_01_i14"> 
</p>
<pre>
flatness : 0.0
u_steps  : 0
v_steps  : 0
</pre>
<a name="s03_04_02_01_i15"><a name="type"></a>
<p>
  The keyword <code>type</code> is followed by a float <em><code> Patch_Type</code></em> which currently must be 
 either 0 or 1. For type 0 only the control points are retained within POV-Ray. This means that a minimal amount of 
 memory is needed but POV-Ray will need to perform many extra calculations when trying to render the patch. Type 1 
 preprocesses the patch into many subpatches. This results in a significant speedup in rendering at the cost of memory. 
</p>
<p>
  <a name="s03_04_02_01_i16"><a name="flatness"></a><a name="s03_04_02_01_i17"><a name="u_steps"></a><a name="s03_04_02_01_i18"><a name="v_steps"></a> 
 The four parameters <code>type</code>, <code> flatness</code>, <code> u_steps</code> and <code>v_steps</code> may 
 appear in any order. Only <code>type</code> is required. They are followed by 16 vectors (4 rows of 4) that define the 
 x, y, z coordinates of the 16 control points which define the patch. The patch touches the four corner points <em><code> 
 <Point_1></code></em>, <em><code> <Point_4></code></em>, <em> <code><Point_13></code></em> and <em> <code> 
 <Point_16></code></em> while the other 12 points pull and stretch the patch into shape. The Bezier surface is 
 enclosed by the convex hull formed by the 16 control points, this is known as the <em>convex hull property</em>. 
</p>
<p>
  The keywords <code>u_steps</code> and <code>v_steps</code> are each followed by integer values which tell how many 
 rows and columns of triangles are the minimum to use to create the surface, both default to 0. The maximum number of 
 individual pieces of the patch that are tested by POV-Ray can be calculated from the following: <em>pieces = 2^u_steps 
 * 2^v_steps</em>. 
</p>
<p>
  This means that you really should keep <code>u_steps</code> and <code> v_steps</code> under 4. Most patches look 
 just fine with <code>u_steps 3</code> and <code>v_steps 3</code>, which translates to 64 subpatches (128 smooth 
 triangles). 
</p>
<p>
  As POV-Ray processes the Bezier patch it makes a test of the current piece of the patch to see if it is flat enough 
 to just pretend it is a rectangle. The statement that controls this test is specified with the <code> flatness</code> 
 keyword followed by a float. Typical flatness values range from 0 to 1 (the lower the slower). The default if none is 
 specified is 0.0. 
</p>
<p>
  If the value for flatness is 0 POV-Ray will always subdivide the patch to the extend specified by <code>u_steps</code> 
 and <code>v_steps</code>. If flatness is greater than 0 then every time the patch is split, POV-Ray will check to see 
 if there is any need to split further. 
</p>
<p>
  There are both advantages and disadvantages to using a non-zero flatness. The advantages include: 
</p>
<p>
  - If the patch is not very curved, then this will be detected and POV-Ray will not waste a lot of time looking at 
 the wrong pieces. 
</p>
<p>
  - If the patch is only highly curved in a couple of places, POV-Ray will keep subdividing there and concentrate its 
 efforts on the hard part. 
</p>
<p>
  The biggest disadvantage is that if POV-Ray stops subdividing at a particular level on one part of the patch and at 
 a different level on an adjacent part of the patch there is the potential for cracking. This is typically visible as 
 spots within the patch where you can see through. How bad this appears depends very highly on the angle at which you 
 are viewing the patch. 
</p>
<p>
  Like triangles, the bicubic patch is not meant to be generated by hand. These shapes should be created by a special 
 utility. You may be able to acquire utilities to generate these shapes from the same source from which you obtained 
 POV-Ray. Here is an example: 
</p>
<pre>
  bicubic_patch {
    type 0
    flatness 0.01
    u_steps 4
    v_steps 4
    <0, 0, 2>, <1, 0, 0>, <2, 0, 0>, <3, 0,-2>,
    <0, 1  0>, <1, 1, 0>, <2, 1, 0>, <3, 1, 0>,
    <0, 2, 0>, <1, 2, 0>, <2, 2, 0>, <3, 2, 0>,
    <0, 3, 2>, <1, 3, 0>, <2, 3, 0>, <3, 3, -2>
  }
</pre>
<p>
  The triangles in a POV-Ray <code>bicubic_patch</code> are automatically smoothed using normal interpolation but it 
 is up to the user (or the user's utility program) to create control points which smoothly stitch together groups of 
 patches. 
</p>
<h4><a name="s03_04_02_02">3.4.2.2 </a>Disc</h4>
<a name="s03_04_02_02_i1"><a name="disc"></a><a name="s03_04_02_02_i2"><a name="disc, keyword"></a><a name="s03_04_02_02_i3">
<p>
  Another flat, finite object available with POV-Ray is the <code> disc</code>. The disc is infinitely thin, it has 
 no thickness. If you want a disc with true thickness you should use a very short cylinder. A disc shape may be defined 
 by: 
</p>
<pre>
DISC:
    disc
    {
        <Center>, <Normal>, Radius [, Hole_Radius]
        [OBJECT_MODIFIERS...]
    }
</pre>
<p>
  Disc default values: <a name="s03_04_02_02_i4"> 
</p>
<pre>
HOLE RADIUS : 0.0
</pre>
<p>
  The vector <em><code><Center></code></em> defines the x, y, z coordinates of the center of the disc. The <em><code> 
 <Normal></code></em> vector describes its orientation by describing its surface normal vector. This is followed 
 by a float specifying the <em> <code> Radius</code></em>. This may be optionally followed by another float specifying 
 the radius of a hole to be cut from the center of the disc. 
</p>
<p class="Note">
  <strong>Note:</strong> The inside of a disc is the inside of the plane that contains the disc. Also 
 note that it is not constrained by the radius of the disc. 
</p>
<h4><a name="s03_04_02_03">3.4.2.3 </a>Mesh</h4>
<a name="s03_04_02_03_i1"><a name="mesh"></a><a name="s03_04_02_03_i2"><a name="mesh, keyword"></a><a name="s03_04_02_03_i3"><a name="s03_04_02_03_i4"><a name="uv_vectors, mesh"></a><a name="s03_04_02_03_i5"><a name="s03_04_02_03_i6"><a name="texture_list, mesh"></a><a name="s03_04_02_03_i7"><a name="s03_04_02_03_i8"><a name="inside_vector, mesh"></a><a name="s03_04_02_03_i9"><a name="s03_04_02_03_i10"><a name="triangle, mesh"></a><a name="s03_04_02_03_i11"><a name="s03_04_02_03_i12"><a name="smooth_triangle, mesh"></a><a name="s03_04_02_03_i13"><a name="s03_04_02_03_i14"><a name="hierarchy, mesh"></a><a name="s03_04_02_03_i15">
<p>
  The <code>mesh</code> object can be used to efficiently store large numbers of triangles. Its syntax is: 
</p>
<pre>
MESH:
    mesh
    {
        MESH_TRIANGLE...
        [MESH_MODIFIER...]
    }
MESH_TRIANGLE:
    triangle
    {
        <Corner_1>, <Corner_2>, <Corner_3>
        [uv_vectors <uv_Corner_1>, <uv_Corner_2>, <uv_Corner_3>]
        [MESH_TEXTURE]
    } |
    smooth_triangle
    {
        <Corner_1>, <Normal_1>,
        <Corner_2>, <Normal_2>,
        <Corner_3>, <Normal_3>
        [uv_vectors <uv_Corner_1>, <uv_Corner_2>, <uv_Corner_3>]
        [MESH_TEXTURE]
    }
MESH_TEXTURE:
  texture { TEXTURE_IDENTIFIER }
  texture_list {
    TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER
  }
MESH_MODIFIER:
    inside_vector <direction> | hierarchy [ Boolean ] |
    OBJECT_MODIFIER
</pre>
<p>
  Mesh default values: <a name="s03_04_02_03_i16"> 
</p>
<pre>
hierarchy : on
</pre>
<p>
  Any number of <code>triangle</code> and/or <code>smooth_triangle</code> statements can be used and each of those 
 triangles can be individually textured by assigning a texture identifier to it. The texture has to be declared before 
 the mesh is parsed. It is not possible to use texture definitions inside the triangle or smooth triangle statements. 
 This is a restriction that is necessary for an efficient storage of the assigned textures. See "<a href="s_106.html#s03_04_02_06">Triangle 
 and Smooth Triangle</a>" for more information on triangles. 
</p>
<p>
  The <code>mesh</code> object can support <code>uv_mapping</code>. For this, per triangle the keyword <code>uv_vectors</code> 
 has to be given, together with three 2D uv-vectors. Each vector specifies a location in the xy-plane from which the 
 texture has to be mapped to the matching points of the triangle. Also see the section <a href="#l133">uv_mapping</a>. 
</p>
<p>
  <a name="s03_04_02_03_i17"> The mesh's components are internally bounded by a bounding box hierarchy to speed up 
 intersection testing. The bounding hierarchy can be turned off with the <code>hierarchy off</code> keyword. This 
 should only be done if memory is short or the mesh consists of only a few triangles. The default is <code>hierarchy on</code>. 
 
</p>
<p>
  Copies of a mesh object refer to the same triangle data and thus consume very little memory. You can easily trace a 
 hundred copies of a 10000 triangle mesh without running out of memory (assuming the first mesh fits into memory). The 
 mesh object has two advantages over a union of triangles: it needs less memory and it is transformed faster. The 
 memory requirements are reduced by efficiently storing the triangles vertices and normals. The parsing time for 
 transformed meshes is reduced because only the mesh object has to be transformed and not every single triangle as it 
 is necessary for unions. 
</p>
<p>
  The mesh object can currently only include triangle and smooth triangle components. That restriction may change, 
 allowing polygonal components, at some point in the future. 
</p>
<h5><a name="s03_04_02_03_01">3.4.2.3.1 </a>Solid Mesh</h5>
<a name="s03_04_02_03_01_i1"><a name="inside_vector"></a><a name="s03_04_02_03_01_i2">
<p>
  Triangle mesh objects (<code>mesh</code> and <code>mesh2</code>) can now be used in CSG objects such as difference 
 and intersect, because, after adding <code>inside_vector</code>, they do have a defined 'inside'. This will only work 
 for well-behaved meshes, which are completely closed volumes. If meshes have any holes in them, this might work, but 
 the results are not guaranteed. 
</p>
<p>
  To determine if a point is inside a triangle mesh, POV-Ray shoots a ray from the point in some arbitrary direction. 
 If this vector intersects an odd number of triangles, the point is inside the mesh. If it intersects an even number of 
 triangles, the point is outside of the mesh. You can specify the direction of this vector. For example, to use <code>+z</code> 
 as the direction, you would add the following line to the triangle mesh description (following all other mesh data, 
 but before the object modifiers). 
</p>
<pre>
  inside_vector <0, 0, 1>
</pre>
<p>
  This change does not have any effect on unions of triangles... these will still be always hollow. 
</p>
<h4><a name="s03_04_02_04">3.4.2.4 </a>Mesh2</h4>
<a name="s03_04_02_04_i1"><a name="vertex_vectors"></a><a name="s03_04_02_04_i2"><a name="normal_vectors"></a><a name="s03_04_02_04_i3"><a name="uv_vectors"></a><a name="s03_04_02_04_i4"><a name="face_indices"></a><a name="s03_04_02_04_i5"><a name="normal_indices"></a><a name="s03_04_02_04_i6"><a name="uv_indices"></a><a name="s03_04_02_04_i7"><a name="texture-list"></a><a name="s03_04_02_04_i8"><a name="mesh2"></a><a name="s03_04_02_04_i9"><a name="mesh2, keyword"></a><a name="s03_04_02_04_i10"><a name="s03_04_02_04_i11"><a name="vertex_vectors, mesh2"></a><a name="s03_04_02_04_i12"><a name="s03_04_02_04_i13"><a name="normal_vectors, mesh2"></a><a name="s03_04_02_04_i14"><a name="s03_04_02_04_i15"><a name="uv_vectors, mesh2"></a><a name="s03_04_02_04_i16"><a name="s03_04_02_04_i17"><a name="texture_list, mesh2"></a><a name="s03_04_02_04_i18"><a name="s03_04_02_04_i19"><a name="face_indices, mesh2"></a><a name="s03_04_02_04_i20"><a name="s03_04_02_04_i21"><a name="normal_indices, mesh2"></a><a name="s03_04_02_04_i22"><a name="s03_04_02_04_i23"><a name="uv_indices, mesh2"></a><a name="s03_04_02_04_i24"><a name="s03_04_02_04_i25"><a name="inside_vector, mesh2"></a><a name="s03_04_02_04_i26">
<p>
  The new mesh syntax is designed for use in conversion from other file formats. 
</p>
<pre>
  MESH2 :
      mesh2{
        VECTORS...
        LISTS...   |
        INDICES... |
        MESH_MODIFIERS
      }
  VECTORS :
      vertex_vectors 
      {
        number_of_vertices,
        <vertex1>, <vertex2>, ...
      }|
      normal_vectors 
      {
        number_of_normals,
        <normal1>, <normal2>, ...
      }|
      uv_vectors 
      {
        number_of_uv_vectors,
        <uv_vect1>, <uv_vect2>, ...
      }
  LISTS :
      texture_list 
      {
        number_of_textures,
        texture { Texture1 },
        texture { Texture2 }, ...
      }|
  INDICES :
      face_indices 
      {
        number_of_faces,
        <index_a, index_b, index_c> [,texture_index [,
                                    texture_index, texture_index]],
        <index_d, index_e, index_f> [,texture_index [,
                                    texture_index, texture_index]],
        ...
      }|
      normal_indices 
      {
        number_of_faces,
        <index_a, index_b, index_c>,
        <index_d, index_e, index_f>,
        ...
      }|
      uv_indices {
        number_of_faces,
        <index_a, index_b, index_c>,
        <index_d, index_e, index_f>,
        ...
      }
  MESH_MODIFIER :
      inside_vector <direction> | OBJECT_MODIFIERS
</pre>
<p>
  <code>mesh2</code> has to be specified in the order <em>VECTORS...</em>, <em>LISTS...</em>, <em>INDICES...</em>. 
 The <code>normal_vectors</code>, <code>uv_vectors</code>, and <code>texture_list</code> sections are optional. If the 
 number of normals equals the number of vertices then the normal_indices section is optional and the indexes from the <code>face_indices</code> 
 section are used instead. Likewise for the <code>uv_indices</code> section. 
</p>
<p class="Note">
  <strong>Note:</strong> that the numbers of uv_indices must equal number of faces. 
</p>
<p>
  The indexes are ZERO-BASED! So the first item in each list has an index of zero. 
</p>
<h5><a name="s03_04_02_04_01">3.4.2.4.1 </a>Smooth and Flat triangles in the same mesh</h5>
<p>
  You can specify both flat and smooth triangles in the same mesh. To do this, specify the smooth triangles first in 
 the <code>face_indices</code> section, followed by the flat triangles. Then, specify normal indices (in the <code>normal_indices</code> 
 section) for only the smooth triangles. Any remaining triangles that do not have normal indices associated with them 
 will be assumed to be flat triangles. 
</p>
<h5><a name="s03_04_02_04_02">3.4.2.4.2 </a>Mesh Triangle Textures</h5>
<p>
  To specify a texture for an individual mesh triangle, specify a single integer texture index following the 
 face-index vector for that triangle. 
</p>
<p>
  To specify three textures for vertex-texture interpolation, specify three integer texture indices (separated by 
 commas) following the face-index vector for that triangle. 
</p>
<p>
  Vertex-texture interpolation and textures for an individual triangle can be mixed in the same mesh 
</p>
<h4><a name="s03_04_02_05">3.4.2.5 </a>Polygon</h4>
<a name="s03_04_02_05_i1"><a name="polygon"></a><a name="s03_04_02_05_i2"><a name="polygon, keyword"></a><a name="s03_04_02_05_i3">
<p>
  The <code>polygon</code> object is useful for creating rectangles, squares and other planar shapes with more than 
 three edges. Their syntax is: 
</p>
<pre>
POLYGON:
    polygon
    {
        Number_Of_Points, <Point_1> <Point_2>... <Point_n>
        [OBJECT_MODIFIER...]
    }
</pre>
<p>
  The float <em><code>Number_Of_Points</code></em> tells how many points are used to define the polygon. The points <em><code> 
 <Point_1></code></em> through <em><code><Point_n></code></em> describe the polygon or polygons. A polygon 
 can contain any number of sub-polygons, either overlapping or not. In places where an even number of polygons overlaps 
 a hole appears. When you repeat the first point of a sub-polygon, it closes it and starts a new sub-polygon's point 
 sequence. This means that all points of a sub-polygon are different. 
</p>
<p>
  If the last sub-polygon is not closed a warning is issued and the program automatically closes the polygon. This is 
 useful because polygons imported from other programs may not be closed, i.e. their first and last point are not the 
 same. 
</p>
<p>
  All points of a polygon are three-dimensional vectors that have to lay on the same plane. If this is not the case 
 an error occurs. It is common to use two-dimensional vectors to describe the polygon. POV-Ray assumes that the z value 
 is zero in this case. 
</p>
<p>
  A square polygon that matches the default planar image map is simply: 
</p>
<pre>
  polygon {
    4,
    <0, 0>, <0, 1>, <1, 1>, <1, 0>
    texture {
      finish { ambient 1 diffuse 0 }
      pigment { image_map { gif "test.gif"  } }
    }
    //scale and rotate as needed here
  }
</pre>
<p>
  The sub-polygon feature can be used to generate complex shapes like the letter "P", where a hole is cut 
 into another polygon: 
</p>
<pre>
  #declare P = polygon {
    12,
    <0, 0>, <0, 6>, <4, 6>, <4, 3>, <1, 3>, <1,0>, <0, 0>, 
    <1, 4>, <1, 5>, <3, 5>, <3, 4>, <1, 4>
  }
</pre>
<p>
  The first sub-polygon (on the first line) describes the outer shape of the letter "P". The second 
 sub-polygon (on the second line) describes the rectangular hole that is cut in the top of the letter "P". 
 Both rectangles are closed, i.e. their first and last points are the same. 
</p>
<p>
  The feature of cutting holes into a polygon is based on the polygon inside/outside test used. A point is considered 
 to be inside a polygon if a straight line drawn from this point in an arbitrary direction crosses an odd number of 
 edges (this is known as <em>Jordan's curve theorem</em>). 
</p>
<p>
  Another very complex example showing one large triangle with three small holes and three separate, small triangles 
 is given below: 
</p>
<pre>
  polygon {
    28,
    <0, 0> <1, 0> <0, 1> <0, 0>          // large outer triangle
    <.3, .7> <.4, .7> <.3, .8> <.3, .7>  // small outer triangle #1
    <.5, .5> <.6, .5> <.5, .6> <.5, .5>  // small outer triangle #2
    <.7, .3> <.8, .3> <.7, .4> <.7, .3>  // small outer triangle #3
    <.5, .2> <.6, .2> <.5, .3> <.5, .2>  // inner triangle #1
    <.2, .5> <.3, .5> <.2, .6> <.2, .5>  // inner triangle #2
    <.1, .1> <.2, .1> <.1, .2> <.1, .1>  // inner triangle #3
  }
</pre>
<h4><a name="s03_04_02_06">3.4.2.6 </a>Triangle and Smooth Triangle</h4>
<a name="s03_04_02_06_i1"><a name="triangle"></a><a name="s03_04_02_06_i2"><a name="triangle, keyword"></a><a name="s03_04_02_06_i3">
<p>
  The <code>triangle</code> primitive is available in order to make more complex objects than the built-in shapes 
 will permit. Triangles are usually not created by hand but are converted from other files or generated by utilities. A 
 triangle is defined by 
</p>
<pre>
TRIANGLE:
    triangle
    {
        <Corner_1>, <Corner_2>, <Corner_3>
        [OBJECT_MODIFIER...]
    }
</pre>
<p>
  where <em><code><Corner_n></code></em> is a vector defining the x, y, z coordinates of each corner of the 
 triangle. 
</p>
<p>
  Because triangles are perfectly flat surfaces it would require extremely large numbers of very small triangles to 
 approximate a smooth, curved surface. However much of our perception of smooth surfaces is dependent upon the way 
 light and shading is done. By artificially modifying the surface normals we can simulate a smooth surface and hide the 
 sharp-edged seams between individual triangles. 
</p>
<p>
  <a name="s03_04_02_06_i4"><a name="smooth_triangle"></a><a name="s03_04_02_06_i5"><a name="smooth_triangle, keyword"></a> 
 <a name="s03_04_02_06_i6"> The <code>smooth_triangle</code> primitive is used for just such purposes. The smooth 
 triangles use a formula called Phong normal interpolation to calculate the surface normal for any point on the 
 triangle based on normal vectors which you define for the three corners. This makes the triangle appear to be a smooth 
 curved surface. A smooth triangle is defined by 
</p>
<pre>
SMOOTH_TRIANGLE:
    smooth_triangle
    {
        <Corner_1>, <Normal_1>, <Corner_2>,
        <Normal_2>, <Corner_3>, <Normal_3>
        [OBJECT_MODIFIER...]
    }
</pre>
<p>
  where the corners are defined as in regular triangles and <em><code> <Normal_n></code></em> is a vector 
 describing the direction of the surface normal at each corner. 
</p>
<p>
  These normal vectors are prohibitively difficult to compute by hand. Therefore smooth triangles are almost always 
 generated by utility programs. To achieve smooth results, any triangles which share a common vertex should have the 
 same normal vector at that vertex. Generally the smoothed normal should be the average of all the actual normals of 
 the triangles which share that point. 
</p>
<p>
  The <code> mesh</code> object is a way to combine many <code>triangle</code> and <code>smooth_triangle</code> 
 objects together in a very efficient way. See "<a href="#l134">Mesh</a>" for details. 
</p>
<p>
 <a name="l133">
<small><strong>More about "uv_mapping"</strong></small>
</a>
 <ul>
  
  <li><small>
   <a href="s_121.html#s03_05_07">3.5.7 UV Mapping</a> in 3.5 Textures
  </small>
  <li><small>
   <a href="s_161.html#s03_08_09_01">3.8.9.1 UV Mapping</a> in 3.8.9 Object Modifiers
  </small>
 </ul>
</p>
<p>
 <a name="l134">
<small><strong>More about "Mesh"</strong></small>
</a>
 <ul>
  
  <li><small>
   <a href="s_106.html#s03_04_02_03">3.4.2.3 Mesh</a> in 3.4.2 Finite Patch Primitives
  </small>
  <li><small>
   <a href="s_106.html#s03_04_02_04">3.4.2.4 Mesh2</a> in 3.4.2 Finite Patch Primitives
  </small>
 </ul>
</p>
 <br> 
<table class="NavBar" width="100%">
  
 <tr>
   
  <td align="left" nowrap="" valign="middle" width="32">
    <a href="s_105.html"><img alt="previous" border="0" src="prev.png"></a> 
   
  </td>
   
  <td align="left" valign="middle" width="30%">
    <a href="s_105.html">3.4.1 Finite Solid Primitives</a> 
  </td>
   
  <td align="center" valign="middle">
    <strong>3.4.2 Finite Patch Primitives</strong> 
  </td>
   
  <td align="right" valign="middle" width="30%">
    <a href="s_107.html">3.4.3 Infinite Solid Primitives</a> 
  </td>
   
  <td align="right" nowrap="" valign="middle" width="32">
    <a href="s_107.html"><img alt="next" border="0" src="next.png"></a> 
   
  </td>
   
 </tr>
  
</table>
 </body> </html>
 |