Initialisation du projet pst-solides3d.git (SVN revision 142)
[pst-solides3d.git] / doc-en / par-new-en.tex
1 \section{Construction from scratch}
2
3 The object \Lkeyword{new} constructs a solid. Two parameters are used: \Lkeyword{sommets}
4 which indicates the list of coordinates of the different vertices, and \Lkeyword{faces} which
5 gives the list of faces of the solid; a face is characterized by a list of the indices of its\Index{vertices}, listed
6 in counterclockwise order
7 when the face is viewed from the exterior of the solid.
8
9 \clearpage
10
11 \subsection{Example 1: a house}
12 \begin{LTXexample}[width=6.5cm]
13 \psset{unit=0.5}
14 \psset{lightsrc=10 -20 50,viewpoint=50 -20 30 rtp2xyz,Decran=50}
15 \begin{pspicture*}(-7,-4)(7,7)
16 \psSolid[object=new,
17 sommets=
18 2 4 3 -2 4 3 -2 -4 3 2 -4 3
19 2 4 0 -2 4 0 -2 -4 0 2 -4 0
20 0 4 5 0 -4 5,
21 faces={
22 [0 1 2 3] [7 6 5 4] [0 3 7 4]
23 [3 9 2] [1 8 0] [8 9 3 0]
24 [9 8 1 2] [6 7 3 2] [2 1 5 6]},
25 num=all,show=all,action=draw]
26 \end{pspicture*}
27 \end{LTXexample}
28
29 Note that the solid \Lkeyword{new} uses the same options as the other solids.
30 For example, we give the same solid as above below, using the parameters
31 \Lkeyword{hollow}, \Lkeyword{incolor}, \Lkeyword{fillcolor}, and \Lkeyword{rm}.
32
33 %% example 2
34 \begin{LTXexample}[width=6.5cm]
35 \psset{unit=0.5}
36 \psset{lightsrc=10 -20 50,viewpoint=50 -20 30 rtp2xyz,Decran=50}
37 \begin{pspicture*}(-7,-3.5)(7,7.5)
38 \psSolid[object=new,fillcolor=red!50,incolor=yellow,
39 action=draw**,hollow,rm=2,
40 sommets=
41 2 4 3 -2 4 3 -2 -4 3 2 -4 3
42 2 4 0 -2 4 0 -2 -4 0 2 -4 0
43 0 4 5 0 -4 5,
44 faces={ [0 1 2 3][7 6 5 4][0 3 7 4]
45 [3 9 2] [1 8 0] [8 9 3 0][9 8 1 2]
46 [6 7 3 2][2 1 5 6]},
47 num=all,show=all]
48 \end{pspicture*}
49 \end{LTXexample}
50
51 \subsection{Example 2: a \Index{hyperboloid} with a fixed radius}
52
53 %\psset{lightsrc=10 20 30,SphericalCoor=true,viewpoint=50 20 30}
54 %\psset{SphericalCoor=true,viewpoint=50 20 30}
55
56
57 As always, the options of the macro \Lcs{psSolid} can handle Postscript code, even \textit{jps code}
58
59 Unlike an example in pure PostScript, where we use the parameters
60 $a$, $b$ and $h$ which are transmitted by the options of PSTricks.
61 In this way one obtains a variable solid constructed from scratch.
62
63 Remark: the code being used comes from a \textit{jps} source used in practice, as in:
64
65 \noindent\url{http://melusine.eu.org/lab/bjps/solide/tour.jps}
66 \begin{LTXexample}[width=6.5cm]
67 \psset{unit=0.75}
68 \psset{lightsrc=10 -20 50,viewpoint=50 -20 30 rtp2xyz,Decran=50}
69 \begin{pspicture*}(-5,-5)(3,5)
70 \psSolid[object=new,fillcolor=red!50,incolor=yellow,
71 hollow, a=10, %% nb d'etages
72 b=20, %% diviseur de 360, nb de meridiens
73 h=8, %% hauteur
74 action=draw**,sommets=
75 /z0 h neg 2 div def
76 a -1 0 {
77 /k exch def
78 0 1 b 1 sub {
79 /i exch def
80 /r z0 h a div k mul add dup mul 4 div 1 add sqrt def
81 360 b idiv i mul cos r mul 360 b idiv i mul sin r mul
82 z0 h a div k mul add
83 } for
84 } for,
85 faces={
86 0 1 a 1 sub {
87 /k exch def
88 k b mul 1 add 1 k 1 add b mul 1 sub {
89 /i exch def
90 [i i 1 sub b i add 1 sub b i add]
91 } for
92 [k b mul k 1 add b mul 1 sub k 2 add b mul 1 sub k 1 add b mul]
93 } for
94 }]
95 \end{pspicture*}
96 \end{LTXexample}
97
98
99
100 \subsection{Example 3: importing external files}
101
102
103 From a file describing a solid in a particular format (other than \texttt{\Index{.obj}} or \texttt{\Index{.off}}),
104 we can create a \texttt{\Index{.dat}} file containing the coordinates of the vertices,
105 and another \texttt{.dat} file containing the tables of indices of the vertices on each face.
106 These files can then be entered as parameters \Lkeyword{sommets} and \Lkeyword{faces}
107 when using the PostScript instruction \Lkeyword{run}.
108
109
110 In the example below, the files \verb+sommets_nefer.dat+
111 and \verb+faces_nefer.dat+ have been placed in the directory of the compiler.
112
113 \begin{LTXexample}[width=5.5cm]
114 \psset{unit=0.4}
115 \definecolor{AntiqueWhite}{rgb}{0.98,0.92,0.84}
116 \begin{pspicture}(-7,-9)(7,7)
117 \psset{lightsrc=30 -40 10}
118 \psset{viewpoint=50 -50 20 rtp2xyz,Decran=50}
119 \psset{RotX=90,sommets= (./sommets_nefer.dat) run}
120 \psSolid[object=new,fillcolor=AntiqueWhite,linewidth=0.5\pslinewidth,
121 faces={(./faces_nefer.dat) run}]%
122 \psSolid[object=new,fillcolor=red,linewidth=0.5\pslinewidth,
123 faces={(./faces_nefer_levres.dat) run}]%
124 \psSolid[object=new,fillcolor=black,
125 faces={(./faces_nefer_sourcils.dat) run}]%
126 \end{pspicture}
127 \hfill
128 \begin{pspicture}(-7,-9)(7,7)
129 \psset{lightsrc=-10 -40 -5,lightintensity=.5}
130 \psset{viewpoint=50 -80 10 rtp2xyz,Decran=50}
131 \psset{RotX=90,RotZ=30,sommets= (./sommets_nefer.dat) run}
132 \psSolid[object=new,fillcolor=AntiqueWhite,linewidth=0.5\pslinewidth,
133 grid,faces={(./faces_nefer.dat) run}]
134 \psSolid[object=new,fillcolor=red,linewidth=0.5\pslinewidth,grid,
135 faces={(./faces_nefer_levres.dat) run}]
136 \psSolid[object=new,fillcolor=black,
137 faces={(./faces_nefer_sourcils.dat) run}]
138 \end{pspicture}
139 \end{LTXexample}
140
141
142 \endinput

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.