initial setup of thesis repository
[cluster_expansion_thesis.git] / little_helpers / tikz / sketch-0.2.161 / Doc / sketch / Object-transforms.html
blobe522cb096c206ca9a1ac41f0740b3186ed808944
1 <html lang="en">
2 <head>
3 <title>Object transforms - 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="Special-objects.html#Special-objects" title="Special objects">
10 <link rel="next" href="Repeated-objects.html#Repeated-objects" title="Repeated objects">
11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12 <!--
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)
24 any later version.
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; }
44 --></style>
45 </head>
46 <body>
47 <div class="node">
48 <p>
49 <a name="Object-transforms"></a>Next:&nbsp;<a rel="next" accesskey="n" href="Repeated-objects.html#Repeated-objects">Repeated objects</a>,
50 Previous:&nbsp;<a rel="previous" accesskey="p" href="Special-objects.html#Special-objects">Special objects</a>,
51 Up:&nbsp;<a rel="up" accesskey="u" href="Introduction-by-example.html#Introduction-by-example">Introduction by example</a>
52 <hr><br>
53 </div>
55 <!-- node-name, next, previous, up -->
56 <h3 class="section">2.5 Transforms</h3>
58 <p><a name="index-transform-58"></a>Now let's add a second copy of the pierced tetrahedron. We'll rotate
59 the copy 90 degrees about the x-axis with the origin as
60 <dfn>center of rotation</dfn>
61 <a name="index-center-of-rotation-59"></a><a name="index-rotation_002c-center-of-60"></a>so we can see the back,
62 then translate it to the right&mdash;in the positive
63 x-direction&mdash;so it doesn't collide with the original. To help
64 us see what's going on, make the back side gray.
65 <a name="index-def-61"></a><a name="index-put-62"></a><a name="index-line-63"></a><a name="index-polygon-64"></a><a name="index-linecolor-65"></a><a name="index-fillcolor-66"></a><a name="index-rotate-67"></a><a name="index-translate-68"></a><a name="index-then-69"></a>
66 <pre class="verbatim">
67 def pierced_tetrahedron {
68 def p1 (0,0,1) def p2 (1,0,0)
69 def p3 (0,1,0) def p4 (-.3,-.5,-.8)
70 polygon(p1)(p2)(p3) % original
71 polygon(p1)(p4)(p2) % bottom
72 polygon(p1)(p3)(p4) % left
73 polygon[fillcolor=lightgray](p3)(p2)(p4) % rear
74 line[linecolor=red](-1,-1,-1)(2,2,2)
76 {pierced_tetrahedron} % tetrahedron in original position
77 put { rotate(90, (0,0,0), [1,0,0]) % copy in new position
78 then translate([2.5,0,0]) } {pierced_tetrahedron}
79 </pre>
80 Here the entire code of the previous example has been wrapped in a
81 definition by forming a <dfn>block</dfn>
82 <a name="index-block-70"></a><a name="index-_0040_007b-_0040_007d_0040r_007b_002c-block-drawable_007d-71"></a>with braces (a single item would not need them). The point
83 definitions nested inside the braces are <dfn>lexically scoped</dfn>.
84 <a name="index-lexical-scope-72"></a><a name="index-scope_002c-identifier-73"></a>Their meaning extends only to the end of the block. The outer
85 <tt>def</tt> is called a <dfn>drawable</dfn>
86 <a name="index-drawable-74"></a>definition
87 <a name="index-definition_002c-drawable-75"></a><a name="index-drawable-definition-76"></a>because it describes something that can be drawn.
89 <p>A drawable definition by itself causes nothing to happen until its
90 name is referenced. Drawable references must be enclosed in curly
91 braces, e.g. <tt>{foo}</tt>, with no intervening
92 <a name="index-white-space-77"></a>white space. In the code
93 above, the first reference
94 <a name="index-reference_002c-drawable-78"></a><tt>{pierced_tetrahedron}</tt>
95 <a name="index-_0040_007bfoo_0040_007d_0040r_007b_002c-drawable-reference_007d-79"></a>is a plain
96 one. Its effect is merely to duplicate the earlier drawing. Almost
97 any series of <code>sketch</code> commands <tt>stuff</tt> may be replaced
98 with <tt>def foo { stuff } {foo}</tt> without changing its meaning.
100 <p>The <tt>put</tt> command supplies a second reference, this time with
101 a <dfn>transform</dfn> applied first. The <tt>rotate</tt>
102 <a name="index-rotate-80"></a><a name="index-rotation-81"></a>transform turns the tetrahedron 90 degrees about the origin. The
103 axis of rotation
104 <a name="index-axis_002c-rotation-82"></a>is the vector [1,0,0]. By the <dfn>right
105 hand rule</dfn>,
106 <a name="index-right-hand-rule-83"></a>this causes the top of the tetrahedron to rotate toward
107 the viewer and the bottom away. The rule receives its name from the
108 following definition:
109 <blockquote>
110 <a name="Right-hand-rule"></a>
111 <strong>Right hand rule.</strong> If the right hand is wrapped around any
112 axis with the thumb pointing in the axis direction, then the fingers
113 curl in the direction of positive rotation about that axis.
114 </blockquote>
115 The <tt>translate</tt>
116 <a name="index-translate-84"></a><a name="index-translation-transform-85"></a><a name="index-transform_002c-translation-86"></a>transform moves the pyramid laterally to
117 the right by adding the vector
118 <a name="index-vector-87"></a>[2.5,0,0] to each vertex
119 coordinate. The result is shown here.
121 <div align="center"><img src="ex050.png" alt="ex050.png"></div>
123 </body></html>