3 <title>Drawing a solid - Sketch
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Sketch">
6 <meta name=
"generator" content=
"makeinfo 4.7">
7 <link title=
"Top" rel=
"start" href=
"index.html#Top">
8 <link rel=
"up" href=
"Introduction-by-example.html#Introduction-by-example" title=
"Introduction by example">
9 <link rel=
"prev" href=
"Drawing-options.html#Drawing-options" title=
"Drawing options">
10 <link rel=
"next" href=
"Special-objects.html#Special-objects" title=
"Special objects">
11 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home" title=
"Texinfo Homepage">
13 Copyright (C) 2005, 2006, 2007, 2008 Eugene K. Ressler.
15 This manual is for `sketch', version 0.2 (build 161),
16 Tuesday, September 08, 2009, a program that converts descriptions of simple
17 three-dimensional scenes into static drawings. This version generates
18 `PSTricks' or `PGF/TikZ' code suitable for use with the
19 TeX document processing system.
21 `Sketch' is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 3, or (at your option)
26 Sketch is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
31 You should have received a copy of the GNU General Public License
32 along with `sketch'; see the file COPYING.txt. If not, see
33 http://www.gnu.org/copyleft.-->
34 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
35 <style type=
"text/css"><!--
36 pre
.display
{ font-family:inherit
}
37 pre
.format
{ font-family:inherit
}
38 pre
.smalldisplay
{ font-family:inherit
; font-size:smaller
}
39 pre
.smallformat
{ font-family:inherit
; font-size:smaller
}
40 pre
.smallexample
{ font-size:smaller
}
41 pre
.smalllisp
{ font-size:smaller
}
42 span
.sc
{ font-variant:small-caps
}
43 span
.roman
{ font-family: serif
; font-weight: normal
; }
49 <a name=
"Drawing-a-solid"></a>Next:
<a rel=
"next" accesskey=
"n" href=
"Special-objects.html#Special-objects">Special objects
</a>,
50 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Drawing-options.html#Drawing-options">Drawing options
</a>,
51 Up:
<a rel=
"up" accesskey=
"u" href=
"Introduction-by-example.html#Introduction-by-example">Introduction by example
</a>
55 <!-- node-name, next, previous, up -->
56 <h3 class=
"section">2.3 Drawing a solid
</h3>
58 <p>Let's try something more exciting.
<code>Sketch
</code> has no notion of a
60 <a name=
"index-solid-28"></a>but polygonal
<dfn>faces
</dfn>
61 <a name=
"index-faces-29"></a>can be used to represent the
62 boundary of a solid. To the previous example, let's add three more
63 triangular polygons to make the faces of an irregular tetrahedron.
64 <a name=
"index-tetrahedron-30"></a><a name=
"index-def-31"></a><a name=
"index-polygon-32"></a>
65 <pre class=
"verbatim">
66 % vertices of the tetrahedron
67 def p1 (
0,
0,
1) def p2 (
1,
0,
0)
68 def p3 (
0,
1,
0) def p4 (-
.3,-
.5,-
.8)
70 % faces of the tetrahedron.
71 polygon(p1)(p2)(p3) % original front polygon
72 polygon(p1)(p4)(p2) % bottom
73 polygon(p1)(p3)(p4) % left
74 polygon(p3)(p2)(p4) % rear
76 % line to pierce the tetrahedron
77 line[linecolor=red](-
1,-
1,-
1)(
2,
2,
2)
79 This example uses
<dfn>definitions
</dfn>,
80 <a name=
"index-definition-33"></a>which begin with
82 <a name=
"index-def-34"></a>These
<dfn>define
</dfn> or give names to points,
83 <a name=
"index-definition_002c-point-35"></a><a name=
"index-point-definition-36"></a>which are then available
84 as
<dfn>references
</dfn>
85 <a name=
"index-reference_002c-point-37"></a>by enclosing the names in parentheses,
87 <a name=
"index-_0028foo_0029_0040r_007b_002c-point-reference_007d-38"></a>The parentheses denote that the names refer to points; they are
88 required. There can be no
89 <a name=
"index-white-space-39"></a>white space between them and the name.
91 <p>As you can see, comments
92 <a name=
"index-comments-40"></a>start with
<tt>%
</tt> as in TeX and extend
93 to the end of the line (though
<tt>#
</tt> will work as well). White
95 <a name=
"index-white-space-41"></a>including spaces, tabs and blank lines, has no effect in the
<code>sketch
</code>
98 <div align=
"center"><img src=
"ex040.png" alt=
"ex040.png"></div>
100 <p class=
"noindent">If we look inside the TeX file produced by
<code>sketch
</code>, there
101 will be only three polygons. The fourth has been
102 <a name=
"index-culling-42"></a>culled because it is
103 a
“back face
”
104 <a name=
"index-back-face-43"></a>of the tetrahedron, invisible to our view. It is
105 unnecessary, and so it is removed.
107 <p>In some drawings, polygons act as zero-thickness solid surfaces with
108 both sides visible rather than as the faces of solid objects, where
109 back faces can be culled. For zero-thickness solids, culling
110 <a name=
"index-culling-44"></a>is a
111 problem. One solution is to use a pair of
<code>sketch
</code> polygons for
112 each zero-thickness face, identical except with opposite vertex
113 orders. This is unwieldy and expensive. A better way is to
114 set the
<code>sketch
</code> internal option
<code>cull
</code> to
<code>false
</code> in
115 the usual
<code>PSTricks
</code> manner.
116 <a name=
"index-cull-45"></a>
117 <pre class=
"verbatim">
118 polygon[cull=false](p1)(p2)(p3)
120 The following shows the same helix
121 <a name=
"index-helix-46"></a>shape drawn first with
122 <tt>cull=true
</tt> (the default) and then
<tt>cull=false
</tt>.
124 <div align=
"center"><img src=
"ex045.png" alt=
"ex045.png"> <a name=
"Helix-with-cull-set-false-then-true"></a></div>
126 <p class=
"noindent">We'll soon see how to produce these helixes with a few lines
127 of
<code>sketch
</code> language code.
129 <p>It may be tempting to turn culling off gratuitously so that vertex order
130 can be ignored. This is not a good idea because output file size and
131 TeX and Postscript processing time both depend on the number of
132 output polygons. Culling usually improves performance by a factor of
133 two. On the other hand, globally setting
<code>cull=false
</code> is
134 reasonable while debugging. See
<a href=
"Global-options.html#Global-options">Global options
</a> and
135 <a href=
"Limits-on-error-detection.html#Limits-on-error-detection">Limits on error detection
</a>.