Debian Codegraph @

texmf-dist/doc/generic/pst-3d/pst-3d-doc.tex

raw
1 %% $Id: pst-3d-doc.tex 289 2010-02-13 14:35:35Z herbert $
2 \documentclass[11pt,english,BCOR10mm,DIV12,bibliography=totoc,parskip=false,smallheadings
3 headexclude,footexclude,oneside,dvipsnames,svgnames]{pst-doc}
4 \listfiles
5
6 \usepackage[utf8]{inputenc}
7 \usepackage{pst-3d}
8 \SpecialCoor
9 \let\pstFV\fileversion
10 \let\belowcaptionskip\abovecaptionskip
11 %
12 \makeatletter
13 \renewcommand*\l@subsection{\bprot@dottedtocline{2}{1.5em}{3.6em}}
14 \renewcommand*\l@subsubsection{\bprot@dottedtocline{3}{3.8em}{4.5em}}
15 \makeatother
16 \def\bgImage{}
17 \lstset{explpreset={pos=l,width=-99pt,overhang=0pt,hsep=\columnsep,vsep=\bigskipamount,rframe={}},
18 escapechar=?}
19 \def\textat{\char064}%
20 \usepackage{shortvrb}
21 \MakeShortVerb{|}
22 \def\la{<}
23 \def\ra{>}
24 \def\arc{\mathrm{arc}}
25 \def\sign{\mathrm{sign}}
26 \def\PiCTeX{\texttt{PiCTeX}}
27 \def\endmacro{}
28
29 \begin{document}
30 \title{\texttt{pst-3d}\\basic three dimension functions \\\small v.\pstFV}
31 \docauthor{Herbert Vo\ss}
32 \author{Timothy Van Zandt\\Herbert Vo\ss}
33 \date{\today}
34
35 \maketitle
36
37 \begin{abstract}
38 This version of \LPack{pst-3d} uses the extended keyval handling
39 of \LPack{pst-xkey}.
40
41 \vfill
42 \noindent
43 Thanks to:
44 \end{abstract}
45
46 \clearpage
47 \tableofcontents
48
49 \clearpage
50
51 \section[PostScript]{PostScript functions \nxLps{SetMatrixThreeD},\nxLps{ProjThreeD}, and \nxLps{SetMatrixEmbed}}
52 \xLps{SetMatrixThreeD}\xLps{ProjThreeD}\xLps{SetMatrixEmbed}
53 The \Index{viewpoint} for 3D coordinates is given by three angles: $\alpha$, $\beta$ and
54 $\gamma$. $\alpha$ and $\beta$ determine the direction from which one is
55 looking. $\gamma$ then determines the orientation of the observing.
56
57 When $\alpha$, $\beta$ and $\gamma$ are all zero, the observer is looking
58 from the negative part of the $y$-axis, and sees the $xz$-plane the way in
59 2D one sees the $xy$ plan. Hence, to convert the 3D coordinates to their 2D
60 project, $\la x, y, z\ra$ map to $\la x, z\ra$.
61
62 When the orientation is different, we rotate the coordinates, and then
63 perform the same projection.
64
65 We move up to latitude $\beta$, over to longitude $\alpha$, and then rotate
66 by $\gamma$. This means that we first rotate around $y$-axis by $\gamma$,
67 then around $x$-axis by $\beta$, and the around $z$-axis by $\alpha$.
68
69 Here are the matrices:
70 \begin{eqnarray*}
71 R_z(\alpha) & = & \left[
72 \begin{array}{ccc}
73 \cos \alpha & -\sin \alpha & 0 \\
74 \sin \alpha & cos \alpha & 0 \\
75 0 & 0 & 1
76 \end{array} \right] \\
77 R_x(\beta) & = & \left[
78 \begin{array}{ccc}
79 1 & 0 & 0 \\
80 0 & \cos \beta & \sin \beta \\
81 0 & -\sin \beta & \cos \beta
82 \end{array} \right] \\
83 R_y(\gamma) & = & \left[
84 \begin{array}{ccc}
85 \cos \gamma & 0 & -\sin \gamma \\
86 0 & 1 & 0 \\
87 \sin \gamma & 0 & \cos \gamma
88 \end{array} \right]
89 \end{eqnarray*}
90
91 The rotation of a coordinate is then performed by the matrix $R_z(\alpha)
92 R_x(\beta) R_y(\gamma)$. The first and third columns of the matrix are the
93 basis vectors of the plan upon which the 3D coordinates are project (the old
94 basis vectors were $\la 1, 0, 0\ra$ and $\la 0, 0, 1$\ra; rotating these
95 gives the first and third columns of the matrix).
96
97 These new basis vectors are:
98 \begin{eqnarray*}
99 \tilde{x} & = & \left[
100 \begin{array}{c}
101 \cos\alpha \cos\gamma - \sin\beta \sin\alpha \sin\gamma \\
102 \sin\alpha \cos\gamma + \sin\beta \cos\alpha \sin\gamma \\
103 \cos\beta \sin\gamma
104 \end{array} \right] \\
105 \tilde{z} & = & \left[
106 \begin{array}{c}
107 -\cos\alpha \sin\gamma - \sin\beta \sin\alpha \cos\gamma \\
108 -\sin\alpha \sin\gamma + \sin\beta \cos\alpha \cos\gamma \\
109 \cos\beta \cos\gamma
110 \end{array} \right]
111 \end{eqnarray*}
112
113 Rather than specifying the angles $\alpha$ and $\beta$, the user gives a
114 vector indicating where the viewpoint is. This new viewpoint is the rotation
115 o the old viewpoint. The old viewpoint is $\la 0, -1, 0\ra$, and so the new
116 viewpoint is
117 \[
118 R_z(\alpha) R_x(\beta) \left[ \begin{array}{c} 0\\-1\\0 \end{array} \right]
119 \, = \,
120 \left[ \begin{array}{c}
121 \cos\beta \sin\alpha \\
122 -\cos\beta \cos\alpha \\
123 \sin\beta
124 \end{array} \right]
125 \, = \,
126 \left[ \begin{array}{c} v_1 \\ v_2 \\ v_3 \end{array} \right]
127 \]
128 Therefore,
129 \begin{eqnarray*}
130 \alpha & = & \arc\tan (v_1 / -v_2) \\
131 \beta & = & \arc\tan (v_3 \sin\alpha / v_1)
132 \end{eqnarray*}
133 Unless $p_1=p_2=0$, in which case $\alpha=0$ and $\beta=\sign(p_3)90$, or
134 $p_1=p_3=0$, in which case $\beta=0$.
135
136
137
138 The syntax of \Lps{SetMatrixThreeD} is
139 $v_1$ $v_2$ $v_3$ $\gamma$ SetMatrixThreeD
140
141 \Lps{SetMatrixThreeD} first computes
142 \[
143 \begin{array}{ll}
144 a=\sin\alpha & b=\cos\alpha\\
145 c=\sin\beta & d=\cos\beta\\
146 e=\sin\gamma & f=\cos\gamma
147 \end{array}
148 \]
149 and then sets \Lps{Matrix3D} to |[|$\tilde{x}$ $\tilde{z}$|]|.
150
151
152 \begin{lstlisting}
153 /SetMatrixThreeD {
154 dup sin /e ED cos /f ED
155 /p3 ED /p2 ED /p1 ED
156 p1 0 eq
157 { /a 0 def /b p2 0 le { 1 } { -1 } ifelse def
158 p3 p2 abs
159 }
160 { p2 0 eq
161 { /a p1 0 lt { -1 } { 1 } ifelse def /b 0 def
162 p3 p1 abs
163 }
164 { p1 dup mul p2 dup mul add sqrt dup
165 p1 exch div /a ED
166 p2 exch div neg /b ED
167 p3 p1 a div
168 }
169 ifelse
170 }
171 ifelse
172 atan dup sin /c ED cos /d ED
173 /Matrix3D
174 [
175 b f mul c a mul e mul sub
176 a f mul c b mul e mul add
177 d e mul
178 b e mul neg c a mul f mul sub
179 a e mul neg c b mul f mul add
180 d f mul
181 ] def
182 } def
183 \end{lstlisting}
184
185 The syntax of \Lps{ProjThreeD} is $x$ $y$ $z$ \Lps{ProjThreeD} $x'$ $y'$
186 where $x'=\la x, y, z\ra \cdot \tilde{x}$ and $y'=\la x, y, z\ra \cdot
187 \tilde{z}$.
188
189 \begin{lstlisting}
190 /ProjThreeD {
191 /z ED /y ED /x ED
192 Matrix3D aload pop
193 z mul exch y mul add exch x mul add
194 4 1 roll
195 z mul exch y mul add exch x mul add
196 exch
197 } def
198 \end{lstlisting}
199
200 To embed 2D $\la x, y\ra$ coordinates in 3D, the user specifies the normal
201 vector and an angle. If we decompose this normal vector into an angle, as
202 when converting 3D coordinates to 2D coordinates, and let $\hat\alpha$,
203 $\hat\beta$ and $\hat\gamma$ be the three angles, then when these angles are
204 all zero the coordinate $\la x, y\ra$ gets mapped to $\la x, 0, y\ra$, and
205 otherwise $\la x, y\ra$ gets mapped to
206 \[
207 R_z(\hat\alpha) R_x(\hat\beta) R_y(\hat\gamma)
208 \left[ \begin{array}{c} x \\ 0 \\ y \end{array} \right]
209 \, = \,
210 \left[ \begin{array}{c}
211 \hat{x}_1 x + \hat{z}_1 y\\
212 \hat{x}_2 x + \hat{z}_2 y\\
213 \hat{x}_3 x + \hat{z}_3 y
214 \end{array} \right]
215 \]
216 where $\hat{x}$ and $\hat{z}$ are the first and third columns of
217 $R_z(\hat\alpha) R_x(\hat\beta) R_y(\hat\gamma)$.
218
219 Now add on a 3D-origin:
220 \[
221 \left[ \begin{array}{c}
222 \hat{x}_1 x + \hat{z}_1 y + x_0\\
223 \hat{x}_2 x + \hat{z}_2 y + y_0\\
224 \hat{x}_3 x + \hat{z}_3 y + z_0
225 \end{array} \right]
226 \]
227
228 Now when we project back onto 2D coordinates, we get
229 \begin{eqnarray*}
230 x' & = & \tilde{x}_1(\hat{x}_1 x + \hat{z}_1 y + x_0) +
231 \tilde{x}_2(\hat{x}_2 x + \hat{z}_2 y + y_0) +
232 \tilde{x}_3(\hat{x}_3 x + \hat{z}_3 y + z_0)\\
233 & = &
234 (\tilde{x}_1\hat{x}_1 + \tilde{x}_2\hat{x}_2 + \tilde{x}_3\hat{x}_3) x\\
235 + (\tilde{x}_1\hat{z}_1 + \tilde{x}_2\hat{z}_2 + \tilde{x}_3\hat{z}_3) y\\
236 + \tilde{x}_1 x_0 + \tilde{x}_2 y_0 + \tilde{z}_3 z_0
237 y' & = & \tilde{z}_1(\hat{x}_1 x + \hat{z}_1 y + x_0) +
238 \tilde{z}_2(\hat{x}_2 x + \hat{z}_2 y + y_0) +
239 \tilde{z}_3(\hat{x}_3 x + \hat{z}_3 y + z_0)\\
240 & = &
241 (\tilde{z}_1\hat{x}_1 + \tilde{z}_2\hat{x}_2 + \tilde{z}_3\hat{x}_3) x\\
242 + (\tilde{z}_1\hat{z}_1 + \tilde{z}_2\hat{z}_2 + \tilde{z}_3\hat{z}_3) y\\
243 + \tilde{z}_1 x_0 + \tilde{z}_2 y_0 + \tilde{z}_3 z_0
244 \end{eqnarray*}
245 Hence, the transformation matrix is:
246 \[
247 \left[ \begin{array}{c}
248 \tilde{x}_1\hat{x}_1 + \tilde{x}_2\hat{x}_2 + \tilde{x}_3\hat{x}_3) \\
249 \tilde{z}_1\hat{x}_1 + \tilde{z}_2\hat{x}_2 + \tilde{z}_3\hat{x}_3) \\
250 \tilde{x}_1\hat{z}_1 + \tilde{x}_2\hat{z}_2 + \tilde{x}_3\hat{z}_3) \\
251 \tilde{z}_1\hat{z}_1 + \tilde{z}_2\hat{z}_2 + \tilde{z}_3\hat{z}_3) \\
252 \tilde{x}_1 x_0 + \tilde{x}_2 y_0 + \tilde{z}_3 z_0 \\
253 \tilde{z}_1 x_0 + \tilde{z}_2 y_0 + \tilde{z}_3 z_0
254 \end{array} \right]
255 \]
256
257 The syntax of \Lps{SetMatrixEmbed} is
258 $x_0$ $y_0$ $z_0$ $\hat{v_1}$ $\hat{v_2}$ $\hat{v_3}$ $\hat{\gamma}$
259 $v_1$ $v_2$ $v_3$ $\gamma$ \Lps{SetMatrixEmbed}
260
261 \Lps{SetMatrixEmbed} first sets |<x1 x2 x3 y1 y2 y3>| to the basis vectors for
262 the viewpoint projection (the tilde stuff above). Then it sets |Matrix3D| to
263 the basis vectors for the embedded plane. Finally, it sets the
264 transformation matrix to the matrix given above.
265
266 \begin{lstlisting}
267 /SetMatrixEmbed {
268 SetMatrixThreeD
269 Matrix3D aload pop
270 /z3 ED /z2 ED /z1 ED /x3 ED /x2 ED /x1 ED
271 SetMatrixThreeD
272 [
273 Matrix3D aload pop
274 z3 mul exch z2 mul add exch z1 mul add 4 1 roll
275 z3 mul exch z2 mul add exch z1 mul add
276 Matrix3D aload pop
277 x3 mul exch x2 mul add exch x1 mul add 4 1 roll
278 x3 mul exch x2 mul add exch x1 mul add
279 3 -1 roll 3 -1 roll 4 -1 roll 8 -3 roll 3 copy
280 x3 mul exch x2 mul add exch x1 mul add 4 1 roll
281 z3 mul exch z2 mul add exch z1 mul add
282 ]
283 concat
284 } def
285 \end{lstlisting}
286
287
288 \section{Keywords}
289 \subsection{\nxLkeyword{viewpoint}}
290
291 \begin{lstlisting}
292 \let\pssetzlength\pssetylength
293 \define@key[psset]{pst-3d}{viewpoint}{%
294 \pst@expandafter\psset@@viewpoint#1 {} {} {} \@nil
295 \let\psk@viewpoint\pst@tempg}
296 \def\psset@@viewpoint#1 #2 #3 #4\@nil{%
297 \begingroup
298 \pssetxlength\pst@dima{#1}%
299 \pssetylength\pst@dimb{#2}%
300 \pssetzlength\pst@dimc{#3}%
301 \xdef\pst@tempg{%
302 \pst@number\pst@dima \pst@number\pst@dimb \pst@number\pst@dimc}%
303 \endgroup}
304 \psset[pst-3d]{viewpoint=1 -1 1}
305 \end{lstlisting}
306
307 \subsection{\nxLkeyword{viewangle}}
308
309 \begin{lstlisting}
310 \define@key[psset]{pst-3d}{viewangle}{\pst@getangle{#1}\psk@viewangle}
311 \psset[pst-3d]{viewangle=0}
312 \end{lstlisting}
313
314 \subsection{\nxLkeyword{normal}}
315
316 \begin{lstlisting}
317 \define@key[psset]{pst-3d}{normal}{%
318 \pst@expandafter\psset@@viewpoint#1 {} {} {} \@nil
319 \let\psk@normal\pst@tempg}
320 \psset[pst-3d]{normal=0 0 1}
321 \end{lstlisting}
322
323
324 \subsection{\nxLkeyword{embedangle}}
325 \begin{lstlisting}
326 \define@key[psset]{pst-3d}{embedangle}{\pst@getangle{#1}\psk@embedangle}
327 \psset[pst-3d]{embedangle=0}
328 \end{lstlisting}
329
330
331 \section{Transformation matrix}
332
333 \begin{lstlisting}
334 /TMSave {
335 tx@Dict /TMatrix known not { /TMatrix { } def /RAngle { 0 } def } if end
336 /TMatrix [ TMatrix CM ] cvx def
337 } def
338 /TMRestore { CP /TMatrix [ TMatrix setmatrix ] cvx def moveto } def
339 /TMChange {
340 TMSave
341 /cp [ currentpoint ] cvx def % ??? Check this later.
342 CM
343 } def
344 \end{lstlisting}
345 Set standard coor. system , with |pt| units and origin at \Index{currentpoint}.
346 This let's us rotate, or whatever, around \TeX's current point, without
347 having to worry about strange coordinate systems that the dvi-to-ps
348 driver might be using.
349 \begin{lstlisting}
350 CP T STV
351 \end{lstlisting}
352
353 Let M = old matrix (on stack), and M' equal current matrix. Then
354 go from M' to M by applying M Inv(M').
355 \begin{lstlisting}
356 CM matrix invertmatrix % Inv(M')
357 matrix concatmatrix % M Inv(M')
358 \end{lstlisting}
359 Now modify transformation matrix:
360 \begin{lstlisting}
361 exch exec
362 \end{lstlisting}
363 Now apply M Inv(M')
364 \begin{lstlisting}
365 concat cp moveto
366 \end{lstlisting}
367
368
369 \section{Macros}
370 \subsection{\nxLcs{ThreeDput}}
371
372 \begin{lstlisting}
373 \def\ThreeDput{\pst@object{ThreeDput}}
374 \def\ThreeDput@i{\@ifnextchar({\ThreeDput@ii}{\ThreeDput@ii(\z@,\z@,\z@)}}
375 \def\ThreeDput@ii(#1,#2,#3){%
376 \pst@killglue\pst@makebox{\ThreeDput@iii(#1,#2,#3)}}
377 \def\ThreeDput@iii(#1,#2,#3){%
378 \begingroup
379 \use@par
380 \if@star\pst@starbox\fi
381 \pst@makesmall\pst@hbox
382 \pssetxlength\pst@dima{#1}%
383 \pssetylength\pst@dimb{#2}%
384 \pssetzlength\pst@dimc{#3}%
385 \leavevmode
386 \hbox{%
387 \pst@Verb{%
388 { \pst@number\pst@dima
389 \pst@number\pst@dimb
390 \pst@number\pst@dimc
391 \psk@normal
392 \psk@embedangle
393 \psk@viewpoint
394 \psk@viewangle
395 \tx@SetMatrixEmbed
396 } \tx@TMChange}%
397 \box\pst@hbox
398 \pst@Verb{\tx@TMRestore}}%
399 \endgroup
400 \ignorespaces}
401 \end{lstlisting}
402
403 \section{Arithmetic}\label{Arithmetic}
404
405 {\verb+\pst@divide+}
406 This is adapted from Donald Arseneau's |shapepar.sty|.
407 Syntax:
408 \begin{verbatim}
409 \pst@divide{<numerator>}{<denominator>}{<command>}
410 \pst@@divide{<numerator>}{<denominator>}
411 \end{verbatim}
412 <numerator> and <denominator> should be dimensions. |\pst@divide| sets
413 <command> to <num>/<den> (in points). |\pst@@divide| sets |\pst@dimg| to
414 <num>/<den>.
415 \begin{lstlisting}
416 \def\pst@divide#1#2#3{%
417 \pst@@divide{#1}{#2}%
418 \pst@dimtonum\pst@dimg{#3}}
419 \def\pst@@divide#1#2{%
420 \pst@dimg=#1\relax
421 \pst@dimh=#2\relax
422 \pst@cntg=\pst@dimh
423 \pst@cnth=67108863
424 \pst@@@divide\pst@@@divide\pst@@@divide\pst@@@divide
425 \divide\pst@dimg\pst@cntg}
426 \end{lstlisting}
427 The number 16 is the level of uncertainty. Use a lower power of 2 for more
428 accuracy (2 is most precise). But if you change it, you must change the
429 repetions of |\pst@@@divide| in |\pst@@divide| above:
430 \[
431 \mbox{precision}^{\mbox{repetitions}} = 65536
432 \]
433 (E.g., $16^4 = 65536$).
434 \begin{lstlisting}
435 \def\pst@@@divide{%
436 \ifnum
437 \ifnum\pst@dimg<\z@-\fi\pst@dimg<\pst@cnth
438 \multiply\pst@dimg\sixt@@n
439 \else
440 \divide\pst@cntg\sixt@@n
441 \fi}
442 \end{lstlisting}
443
444 {\verb+\pst@pyth+}
445 Syntax:
446 \begin{verbatim}
447 \pst@pyth{<dim1>}{<dim2>}{<dimen register>}
448 \end{verbatim}
449 <dimen register> is set to $((dim1)^2+(dim2)^2)^{1/2}$.
450
451 The algorithm is copied from \PiCTeX, by Michael Wichura (with permission).
452 Here is his description:
453 \begin{quote}
454 Suppose $x>0$, $y>0$. Put $s = x+y$. Let $z = (x^2+y^2)^{1/2}$. Then $z =
455 s\times f$, where
456 \[
457 f = (t^2 + (1-t)^2)^{1/2} = ((1+\tau^2)/2)^{1/2}
458 \]
459 and $t = x/s$ and $\tau = 2(t-1/2)$.
460 \end{quote}
461 \begin{lstlisting}
462 \def\pst@pyth#1#2#3{%
463 \begingroup
464 \pst@dima=#1\relax
465 \ifnum\pst@dima<\z@\pst@dima=-\pst@dima\fi % dima=abs(x)
466 \pst@dimb=#2\relax
467 \ifnum\pst@dimb<\z@\pst@dimb=-\pst@dimb\fi % dimb=abs(y)
468 \advance\pst@dimb\pst@dima % dimb=s=abs(x)+abs(y)
469 \ifnum\pst@dimb=\z@
470 \global\pst@dimg=\z@ % dimg=z=sqrt(x^2+y^2)
471 \else
472 \multiply\pst@dima 8\relax % dima= 8abs(x)
473 \pst@@divide\pst@dima\pst@dimb % dimg =8t=8abs(x)/s
474 \advance\pst@dimg -4pt % dimg = 4tau = (8t-4)
475 \multiply\pst@dimg 2
476 \pst@dimtonum\pst@dimg\pst@tempa
477 \pst@dima=\pst@tempa\pst@dimg % dima=(8tau)^2
478 \advance\pst@dima 64pt % dima=u=[64+(8tau)^2]/2
479 \divide\pst@dima 2\relax % =(8f)^2
480 \pst@dimd=7pt % initial guess at sqrt(u)
481 \pst@@pyth\pst@@pyth\pst@@pyth % dimd=sqrt(u)
482 \pst@dimtonum\pst@dimd\pst@tempa
483 \pst@dimg=\pst@tempa\pst@dimb
484 \global\divide\pst@dimg 8 % dimg=z=(8f)*s/8
485 \fi
486 \endgroup
487 #3=\pst@dimg}
488 \def\pst@@pyth{% dimd = g <-- (g + u/g)/2
489 \pst@@divide\pst@dima\pst@dimd
490 \advance\pst@dimd\pst@dimg
491 \divide\pst@dimd 2\relax}
492 \end{lstlisting}
493
494
495 {\verb+\pst@sinandcos+}
496 Syntax:
497 \begin{verbatim}
498 \pst@sinandcos{<dim>}{<int>}
499 \end{verbatim}
500 <dim>, in |sp| units, should equal 100,000 times the angle, in degrees
501 between 0 and 90. <int> should equal the angle's quadrant (0, 1, 2 or 3).
502 |\pst@dimg| is set to $\sin(\theta)$ and |\pst@dimh| is set to
503 $\cos(\theta)$ (in pt's).
504
505 The algorithms uses the usual McLaurin expansion.
506 \begin{lstlisting}
507 \def\pst@sinandcos#1{%
508 \begingroup
509 \pst@dima=#1\relax
510 \pst@dima=.366022\pst@dima %Now 1pt=1/32rad
511 \pst@dimb=\pst@dima % dimb->32sin(angle) in pts
512 \pst@dimc=32\p@ % dimc->32cos(angle) in pts
513 \pst@dimtonum\pst@dima\pst@tempa
514 \pst@cntb=\tw@
515 \pst@cntc=-\@ne
516 \pst@cntg=32
517 \loop
518 \ifnum\pst@dima>\@cclvi % 256
519 \pst@dima=\pst@tempa\pst@dima
520 \divide\pst@dima\pst@cntg
521 \divide\pst@dima\pst@cntb
522 \ifodd\pst@cntb
523 \advance\pst@dimb \pst@cntc\pst@dima
524 \pst@cntc=-\pst@cntc
525 \else
526 \advance\pst@dimc by \pst@cntc\pst@dima
527 \fi
528 \advance\pst@cntb\@ne
529 \repeat
530 \divide\pst@dimb\pst@cntg
531 \divide\pst@dimc\pst@cntg
532 \global\pst@dimg\pst@dimb
533 \global\pst@dimh\pst@dimc
534 \endgroup}
535 \end{lstlisting}
536
537
538 {\verb+\pst@getsinandcos+}
539 |\pst@getsinandcos| normalizes the angle to be in the first quadrant, sets
540 |\pst@quadrant| to 0 for the first quadrant, 1 for the second, 2 for the
541 third, and 3 for the fourth, invokes |\pst@sinandcos|, and sets |\pst@sin|
542 to the sine and |\pst@cos| to the cosine.
543 \begin{lstlisting}
544 \def\pst@getsinandcos#1{%
545 \pst@dimg=100000sp
546 \pst@dimg=#1\pst@dimg
547 \pst@dimh=36000000sp
548 \pst@cntg=0
549 \loop
550 \ifnum\pst@dimg<\z@
551 \advance\pst@dimg\pst@dimh
552 \repeat
553 \loop
554 \ifnum\pst@dimg>\pst@dimh
555 \advance\pst@dimg-\pst@dimh
556 \repeat
557 \pst@dimh=9000000sp
558 \def\pst@tempg{%
559 \ifnum\pst@dimg<\pst@dimh\else
560 \advance\pst@dimg-\pst@dimh
561 \advance\pst@cntg\@ne
562 \ifnum\pst@cntg>\thr@@ \advance\pst@cntg-4 \fi
563 \expandafter\pst@tempg
564 \fi}%
565 \pst@tempg
566 \chardef\pst@quadrant\pst@cntg
567 \ifdim\pst@dimg=\z@
568 \def\pst@sin{0}%
569 \def\pst@cos{1}%
570 \else
571 \pst@sinandcos\pst@dimg
572 \pst@dimtonum\pst@dimg\pst@sin
573 \pst@dimtonum\pst@dimh\pst@cos
574 \fi}
575 \end{lstlisting}
576
577
578 \section{Tilting}
579
580 {\verb+\pstilt+}
581 \begin{lstlisting}
582 \def\pstilt#1{\pst@makebox{\pstilt@{#1}}}
583 \def\pstilt@#1{%
584 \begingroup
585 \leavevmode
586 \pst@getsinandcos{#1}%
587 \hbox{%
588 \ifcase\pst@quadrant
589 \kern\pst@cos\dp\pst@hbox
590 \pst@dima=\pst@cos\ht\pst@hbox
591 \ht\pst@hbox=\pst@sin\ht\pst@hbox
592 \dp\pst@hbox=\pst@sin\dp\pst@hbox
593 \or
594 \kern\pst@sin\ht\pst@hbox
595 \pst@dima=\pst@sin\dp\pst@hbox
596 \ht\pst@hbox=\pst@cos\ht\pst@hbox
597 \dp\pst@hbox=\pst@cos\dp\pst@hbox
598 \or
599 \kern\pst@cos\ht\pst@hbox
600 \pst@dima=\pst@sin\dp\pst@hbox
601 \pst@dimg=\pst@sin\ht\pst@hbox
602 \ht\pst@hbox=\pst@sin\dp\pst@hbox
603 \dp\pst@hbox=\pst@dimg
604 \or
605 \kern\pst@sin\dp\pst@hbox
606 \pst@dima=\pst@sin\ht\pst@hbox
607 \pst@dimg=\pst@cos\ht\pst@hbox
608 \ht\pst@hbox=\pst@cos\dp\pst@hbox
609 \dp\pst@hbox=\pst@dimg
610 \fi
611 \pst@Verb{%
612 { [ 1 0
613 \pst@cos\space \ifnum\pst@quadrant>\@ne neg \fi
614 \pst@sin\space
615 \ifnum\pst@quadrant>\z@\ifnum\pst@quadrant<\thr@@ neg \fi\fi
616 \ifodd\pst@quadrant exch \fi
617 0 0
618 ] concat
619 } \tx@TMChange}%
620 \box\pst@hbox
621 \pst@Verb{\tx@TMRestore}%
622 \kern\pst@dima}%
623 \endgroup}
624 \end{lstlisting}
625
626
627 {\verb+\psTilt+}
628 \begin{lstlisting}
629 \def\psTilt#1{\pst@makebox{\psTilt@{#1}}}
630 \def\psTilt@#1{%
631 \begingroup
632 \leavevmode
633 \pst@getsinandcos{#1}%
634 \hbox{%
635 \ifodd\pst@quadrant
636 \pst@@divide{\dp\pst@hbox}{\pst@cos\p@}%
637 \ifnum\pst@quadrant=\thr@@\kern\else\pst@dima=\fi\pst@sin\pst@dimg
638 \pst@@divide{\ht\pst@hbox}{\pst@cos\p@}%
639 \ifnum\pst@quadrant=\@ne\kern\else\pst@dima=\fi\pst@sin\pst@dimg
640 \else
641 \ifdim\pst@sin\p@=\z@
642 \@pstrickserr{\string\psTilt\space angle cannot be 0 or 180}\@ehpa
643 \def\pst@sin{.7071}%
644 \def\pst@cos{.7071}%
645 \fi
646 \pst@@divide{\dp\pst@hbox}{\pst@sin\p@}%
647 \ifnum\pst@quadrant=\z@\kern\else\pst@dima=\fi\pst@cos\pst@dimg
648 \pst@@divide{\ht\pst@hbox}{\pst@sin\p@}%
649 \ifnum\pst@quadrant=\tw@\kern\else\pst@dima=\fi\pst@cos\pst@dimg
650 \fi
651 \ifnum\pst@quadrant>\@ne
652 \pst@dimg=\ht\pst@hbox
653 \ht\pst@hbox=\dp\pst@hbox
654 \dp\pst@hbox=\pst@dimg
655 \fi
656 \pst@Verb{%
657 { [ 1 0
658 \pst@cos\space \pst@sin\space
659 \ifodd\pst@quadrant exch \fi
660 \tx@Div
661 \ifnum\pst@quadrant>\z@\ifnum\pst@quadrant<\thr@@ neg \fi\fi
662 \ifnum\pst@quadrant>\@ne -1 \else 1 \fi
663 0 0
664 ] concat
665 } \tx@TMChange}%
666 \box\pst@hbox
667 \pst@Verb{\tx@TMRestore}%
668 \kern\pst@dima}%
669 \endgroup}
670 \end{lstlisting}
671
672
673 {\verb+\psset@Tshadowsize,\psTshadowsize+}
674 \begin{lstlisting}
675 \define@key[psset]{pst-3d}{Tshadowsize}{%
676 \pst@checknum{#1}\psTshadowsize}
677 \psset[pst-3d]{Tshadowsize=1}
678 \end{lstlisting}
679
680
681 {\verb+\psset@Tshadowangle,\psk@Tshadowangle+}
682 \begin{lstlisting}
683 \define@key[psset]{pst-3d}{Tshadowangle}{%
684 \pst@getangle{#1}\psk@Tshadowangle}
685 \psset[pst-3d]{Tshadowangle=60}
686 \end{lstlisting}
687
688
689 {\verb+\psset@Tshadowcolor,\psTshadowcolor+}
690 \begin{lstlisting}
691 \define@key[psset]{pst-3d}{Tshadowcolor}{%
692 \pst@getcolor{#1}\psTshadowcolor}
693 \psset[pst-3d]{Tshadowcolor=lightgray}
694 \end{lstlisting}
695
696
697 {\verb+\psshadow+}
698 \begin{lstlisting}
699 \def\psshadow{\def\pst@par{}\pst@object{psshadow}}
700 \def\psshadow@i{\pst@makebox{\psshadow@ii}}
701 \def\psshadow@ii{%
702 \begingroup
703 \use@par
704 \leavevmode
705 \pst@getsinandcos{\psk@Tshadowangle}%
706 \hbox{%
707 \lower\dp\pst@hbox\hbox{%
708 \pst@Verb{%
709 { [ 1 0
710 \pst@cos\space \psTshadowsize mul
711 \ifnum\pst@quadrant>\@ne neg \fi
712 \pst@sin\space \psTshadowsize mul
713 \ifnum\pst@quadrant>\z@\ifnum\pst@quadrant<\thr@@ neg \fi\fi
714 \ifodd\pst@quadrant exch \fi
715 0 0
716 ] concat
717 } \tx@TMChange}}%
718 \hbox to\z@{{\@nameuse{\psTshadowcolor}\copy\pst@hbox\hss}}%
719 \pst@Verb{\tx@TMRestore}%
720 \box\pst@hbox}%
721 \endgroup}
722 \end{lstlisting}
723
724 \section{Affin Transformations}
725
726 \begin{BDef}
727 \Lcs{psAffinTransform}\OptArgs\Largb{transformation matrix}\Largb{object}
728 \end{BDef}
729
730 \begin{LTXexample}[width=3cm]
731 \pspicture(3,6)\psset{linewidth=4pt,arrows=->}
732 \psline(0,0)(1.5,0)(3,3)\rput*(2.25,1.5){foo}
733 \psAffinTransform{0.5 0 0 2 0 0}{\color{red}%
734 \psline[linecolor=red](0,0)(1.5,0)(3,3)\rput*(2.25,1.5){foo}}%
735 \endpspicture
736 \end{LTXexample}
737
738 The transformation matrix must be a list of 6 values divided by a space.
739 For a translation modify the last two values of $1 0 0 1 dx dy$. The values for
740 $dx$ and $dy$ must be of the unit pt! For a rotation
741 we have the transformation matrix
742
743 \begin{align}
744 \left[\begin{aligned} \cos(\alpha) & \sin(\alpha) & 0 \\
745 -\sin(\alpha) & \cos(\alpha) & 0 \\
746 0 & 0 & 1\end{aligned}\right]
747 \end{align}
748
749 For \Lcs{psAffinTransform} the four values have to be modifies \texttt{a cos a sin a sin neg a cos 0 0}.
750 Tilting can be done with $sx 0 0 sy 0 0$. All effects can be combined.
751
752 \begin{LTXexample}[width=3cm]
753 \pspicture(3,6)\psset{linewidth=4pt,arrows=->}
754 \psline(0,0)(1.5,0)(3,3)\rput*(2.25,1.5){foo}
755 \psAffinTransform{0.5 0.8 0.3 2 20 -20}{\color{red}%
756 \psline[linecolor=red](0,0)(1.5,0)(3,3)\rput*(2.25,1.5){foo}}%
757 \endpspicture
758 \end{LTXexample}
759
760
761 \clearpage
762 \section{List of all optional arguments for \texttt{pst-3d}}
763
764 \xkvview{family=pst-3d,columns={key,type,default}}
765
766
767
768
769
770 \nocite{*}
771 \bgroup
772 \RaggedRight
773 \bibliographystyle{plain}
774 \bibliography{pst-3d-doc}
775 \egroup
776
777 \printindex
778
779
780
781
782
783 \end{document}