Initialisation du projet pst-solides3d.git (SVN revision 142)
[pst-solides3d.git] / doc-en / par-tube-en.tex
1 \section{Tubes}
2
3 This section is about to substitute a curve in two or three dimensions (2D or 3D),
4 that are setup parameterised, by a \Index{tube}, where the initial curve is the axes and
5 we can choose the radius and grid. We find some mathematical elements concerning
6 these objects on the following websites:
7
8 \centerline{\url{http://fr.wikipedia.org/wiki/Tube_(math\%C3\%A9matiques)}}
9
10 \centerline{\url{http://www.mathcurve.com/surfaces/tube/tube.shtml}}
11
12 As usual, the \texttt{pst-solides3d} package offers two possibilities to draw the tubes:
13 \begin{itemize}
14 \item via PSTricks and the argument \Lkeyword{object} of \Lcs{psSolid}
15 \item directly with \verb+\codejps+
16 \end{itemize}
17
18 \encadre{It is often advisable to calculate in advance, by hand or with a preferred software, the first derivatives of the parametric functions which define the coordinates.}
19
20 However, if this derivative isn't defined explicitly by the user, the package makes some approximate calculations, but the result then is not always sufficient.
21
22
23 \subsection{Usage with PSTricks}
24
25 \subsubsection{Give your curves a relief}
26 ``\textit{Donnez du relief \`{a} vos courbes}'', this is the title of the article
27 from Robert \textsc{Ferr\'{e}ol}, available on:
28
29 \url{http://mapage.noos.fr/r.ferreol/atelecharger/textes/relief/courbes\%20en\%20relief.html}
30
31 from who the following functions were borrowed and which are analogous to a
32 Lissajous figure enrolled around a cylinder.
33
34
35 \begin{LTXexample}[pos=t]
36 \begin{pspicture}(-3.5,-4)(4,4)
37 \psset{lightsrc=80 30 30,viewpoint=100 45 30 rtp2xyz,Decran=110,linewidth=0.2pt}
38 \defFunction[algebraic]{Func}(t){2.5*cos(t)}{2.5*sin(t)}{2*cos(5*t)}
39 \defFunction[algebraic]{Func'}(t){-2.5*sin(t)}{2.5*cos(t)}{-10*sin(5*t)}
40 \psSolid[object=courbe,range=0 6.28,hue=0 1 0.7 1,
41 ngrid=360 8,function=Func,r=0.15]
42 \end{pspicture}
43 \end{LTXexample}
44
45
46 The argument \texttt{\Lkeyword{object}=\Lkeyval{courbe}} with the parameters
47 \Lkeyword{r}, \Lkeyword{function} and \Lkeyword{range} is used to specify
48 the radius of the tube, the name of the function to be used and the range.
49
50 We can also refine the grid with the optional argument
51 \texttt{\Lkeyword{ngrid}=$n_1$ $n_2$} where $n_1$ represents the number of
52 vertices of a section of a tube (if $n_1 = 6$, this gives a tube with a
53 hexagonal section) and $n_2$ represents the number of divisions along it.
54
55
56 \subsubsection{A \Index{hairline curve} is produced with the radius \texttt{r=0}}
57
58 And thus, no fear to specify the derived function.
59
60 \begin{LTXexample}[pos=t]
61 \begin{pspicture}(-3.5,-4)(4,4)
62 \psset{lightsrc=80 30 30,viewpoint=100 45 30 rtp2xyz,Decran=110}
63 \defFunction[algebraic]{FI}(t){2.5*cos(t)}{2.5*sin(t)}{2*cos(5*t)}
64 \psSolid[object=courbe,range=0 6.28,linewidth=2pt,linecolor=blue,function=FI,r=0]
65 \end{pspicture}
66 \end{LTXexample}
67
68
69 \subsection{Usage with \texttt{\textbackslash{}codejps}}
70
71 The syntax is \texttt{\textbackslash{}codejps\{t\_min t\_max (name\_function)
72 radius\_tube [n1 n2] newtube\}}.
73
74
75 \begin{LTXexample}[pos=t]
76 \begin{pspicture}(-3.5,-3.5)(4,3.5)
77 \psset{lightsrc=80 30 30,viewpoint=100 45 90 rtp2xyz,Decran=100,linewidth=0.2pt}
78 \codejps{
79 /rpn {tx@AlgToPs begin AlgToPs end cvx exec} def
80 /xc {((2+1*cos(2.75*t))*cos(t)) rpn } def
81 /yc {((2+1*cos(2.75*t))*sin(t)) rpn } def
82 /zc {(1*sin(2.75*t)) rpn } def
83 /xc' {(-2.75*sin(2.75*t)*cos(t)-(2+cos(2.75*t))*sin(t)) rpn } def
84 /yc' {(-2.75*sin(2.75*t)*sin(t)+(2+cos(2.75*t))*cos(t)) rpn } def
85 /zc' {(2.75*cos(2.75*t)) rpn } def
86 /g { 3 dict begin /t exch def xc yc zc end } def
87 /g' { % first derivative
88 3 dict begin /t exch def xc' yc' zc' end } def
89 /solenoide{
90 % t_min t_max (name_function) radius_tube [resolution]
91 0 25.2 (g) 0.1 [360 8] newtube dup [0 1] solidputhuecolors} def
92 solenoide
93 drawsolid**
94 }%
95 \end{pspicture}
96 \end{LTXexample}
97
98 \subsection{Improving the speed of readout}
99
100 The curve with the name ``\textit{horopter}'' is the subject of this website:
101
102 \centerline{\url{http://www.mathcurve.com/courbes3d/horoptere/horoptere.shtml}}
103
104 \subsubsection{Obtaining the curve directly}
105
106 The following lines allow us to calculate the points and draw the curve.
107 The \Index{resolution} \texttt{\Lkeyword{ngrid}=72 12} of the curve was increased, so some
108 more calculation time to produce the result, which some will judge as very long.
109 \begin{verbatim}
110 \begin{pspicture}(-7,-2)(7,4)
111 \psset{lightsrc=80 30 30}
112 \psset{viewpoint=1000 60 20 rtp2xyz,Decran=1000}
113 \psframe(-7,-2)(7,4)
114 \psset{solidmemory}
115 \codejps{/a 2 def /b 2 def}%
116 \defFunction[algebraic]{F3}(t)
117 {a*(1+cos(t))}
118 {b*tan(t/2)}
119 {a*sin(t)}
120 \defFunction[algebraic]{F3'}(t)
121 {-a*sin(t)}
122 {b*(1+tan(1/2*t)^2)}
123 {a*cos(t)}
124 \psSolid[object=courbe,
125 range=-2.7468 2.7468,
126 ngrid=72 12,
127 function=F3,hue=0 1 0.7 1,
128 action=none,name=H1,
129 r=1]%
130 \psSolid[object=cylindrecreux,
131 h=20,r=1,RotX=90,
132 incolor=green!30,action=none,
133 name=C1,
134 ngrid=36 36](2,10,0)
135 \psSolid[object=fusion,
136 base=H1 C1]
137 \composeSolid
138 \end{pspicture}
139 \end{verbatim}
140
141 \subsubsection{Saving the parameters of the curve}
142
143 If this curve is used several times, it is advisable to backup all the
144 characteristics of that curve, like:
145 coordinates of the vertices, list of colours of the faces with placing
146 the last command \texttt{\Lkeyword{action}=\Lkeyval{writesolid}}:
147 \begin{verbatim}
148 \psSolid[object=fusion,
149 base=H1 C1,
150 file=horoptere,
151 action=writesolid]
152 \end{verbatim}
153 The following sequence \Cadre{LaTeX fichier.tex->dvips->GSview
154 (Windows) or gv (Linux)} will generate 4 files:
155 \begin{itemize}
156 \item \texttt{horoptere-couleurs.dat} $\rightarrow$ the colours of the faces;
157 \item \texttt{horoptere-faces.dat} $\rightarrow$ the list of faces;
158 \item \texttt{horoptere-sommets.dat} $\rightarrow$ the list of vertices;
159 \item \texttt{horoptere-io.dat} $\rightarrow$ the number of faces and vertices.
160 \end{itemize}
161
162 then read and execute the files with the command:
163 \texttt{\textbackslash{}psSolid[object=datfile,file=horoptere]}, the time saved can be quite significant
164
165
166
167 \encadre{By default, under Windows and Linux, the security of files on the hard drive is activated and doesn't allow to write on the drive.
168 To deactivate that security option, more or less temporarily, here the two corresponding procedures:
169
170 \begin{description}
171
172 \item[Linux:] The advice from Jean-Michel \textsc{Sarlat}: the simplest will be to use GhostScript directly, within the console. As there is no image to wait for:
173
174 \$$>$ gs -dNOSAFER monfichier.ps quit.ps
175 \item[Windows:] Within the menue \texttt{Options}, the option
176 \textsf{Security of files} must be turned to unchecked.
177 \end{description}}
178
179 \subsubsection{The plot of the curve}
180
181 \begin{LTXexample}[width=9cm]
182 \begin{pspicture}(-5,-3.5)(4,3)
183 \psset{lightsrc=80 30 30}
184 \psset{viewpoint=100 60 20 rtp2xyz,
185 Decran=75}
186 \psframe*[linecolor=cyan!30](-4.5,-3)(3.5,3)
187 \psSolid[object=datfile,file=./horoptere]
188 \end{pspicture}
189 \end{LTXexample}
190
191
192 \clearpage
193 \subsection{Some other examples}
194
195
196 \subsubsection{A straight line}
197
198 \begin{LTXexample}[width=7cm]
199 \begin{pspicture}(-3.5,-2)(3.5,2)
200 \psset{viewpoint=100 -20 20 rtp2xyz,
201 Decran=75,unit=0.8}
202 \psSolid[object=grille,base=-4 4 -4 4]%
203 \defFunction[algebraic]{FIV}(t){t}{t}{0.5}
204 \defFunction[algebraic]{FIV'}(t){1}{1}{0}
205 \psSolid[object=courbe,
206 range=-4 4, ngrid=16 16,
207 function=FIV, r=0.5]
208 \end{pspicture}
209 \end{LTXexample}
210
211
212
213 \subsubsection{A \Index{hypocycloid}}
214
215 \begin{LTXexample}[width=7cm]
216 \begin{pspicture}(-3.5,-3)(3.5,3)
217 \psset{viewpoint=100 20 45 rtp2xyz,
218 Decran=75,unit=0.7}
219 \psSolid[object=grille,base=-5 5 -5 5]%
220 \defFunction[algebraic]{FII}(t)
221 {4*cos(t)+cos(4*t)/2}
222 {4*sin(t)-sin(4*t)/2}
223 {1}
224 \defFunction[algebraic]{FII'}(t)
225 {-4*sin(t)-2*sin(4*t)}
226 {4*cos(t)-2*cos(4*t)}
227 {0}
228 \psSolid[object=courbe,
229 range=0 6.28,ngrid=90 16,
230 function=FII,r=1]
231 \end{pspicture}
232 \end{LTXexample}
233
234 \clearpage
235
236 \subsubsection{The spring of Gaston}
237
238 \begin{LTXexample}[width=7cm]
239 \begin{pspicture}(-3.5,-4)(3.5,4.5)
240 \psset{lightsrc=80 30 30,
241 viewpoint=100 20 20 rtp2xyz,Decran=50}
242 \defFunction[algebraic]{FIII}(t)
243 {(t^2+3)*sin(15*t)}
244 {(t^2+3)*cos(15*t)}{2*t}
245 \defFunction[algebraic]{FIII'}(t)
246 {2*t*sin(15*t)+15*(t^2+3)*cos(15*t)}
247 {2*t*cos(15*t)-15*(t^2+3)*sin(15*t)}{2}
248 \psSolid[object=courbe,
249 range=-2 2,ngrid=360 6,
250 function=FIII,hue=0.2 0.3,
251 linewidth=0.1pt,r=0.2]
252 \end{pspicture}
253 \end{LTXexample}
254
255
256 \endinput
257

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.