1 /*
2 
3 -Procedure pltar_c ( Compute area of plate set )
4 
5 -Abstract
6 
7    Compute the total area of a collection of triangular plates.
8 
9 -Disclaimer
10 
11    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
12    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
13    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
14    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
15    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
16    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
17    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
18    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
19    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
20    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
21 
22    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
23    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
24    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
25    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
26    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
27    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
28 
29    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
30    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
31    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
32    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
33 
34 -Required_Reading
35 
36    None.
37 
38 -Keywords
39 
40    DSK
41    GEOMETRY
42    MATH
43 
44 */
45 
46    #include "SpiceUsr.h"
47    #include "SpiceZfc.h"
48    #include "SpiceZst.h"
49    #undef pltar_c
50 
51 
pltar_c(SpiceInt nv,ConstSpiceDouble vrtces[][3],SpiceInt np,ConstSpiceInt plates[][3])52    SpiceDouble pltar_c ( SpiceInt           nv,
53                          ConstSpiceDouble   vrtces [][3],
54                          SpiceInt           np,
55                          ConstSpiceInt      plates [][3]  )
56 /*
57 
58 -Brief_I/O
59 
60    Variable  I/O  Description
61    --------  ---  --------------------------------------------------
62    nv         I   Number of vertices.
63    vrtces     I   Array of vertices.
64    np         I   Number of triangular plates.
65    plates     I   Array of plates.
66 
67    The function returns the total area of the set of plates.
68 
69 -Detailed_Input
70 
71    nv             is the number of vertices comprising the plate set.
72 
73    vrtces         is an array containing the plate model's vertices.
74                   Elements
75 
76                      vrtces[i-1][0]
77                      vrtces[i-1][1]
78                      vrtces[i-1][2]
79 
80                   are, respectively, the X, Y, and Z components of
81                   the ith vertex, where i ranges from 1 to `nv'.
82 
83                   This routine doesn't associate units with the
84                   vertices.
85 
86 
87    np             is the number of triangular plates comprising the
88                   plate set.
89 
90    plates         is an array containing 3-tuples of integers
91                   representing the set of plates. The elements of
92                   `plates' are vertex indices. The vertex indices are
93                   1-based: vertices have indices ranging from 1 to
94                   `nv'. The elements
95 
96                      plates[i-1][0]
97                      plates[i-1][1]
98                      plates[i-1][2]
99 
100                   are, respectively, the indices of the vertices
101                   comprising the ith plate.
102 
103                   Note that the order of the vertices of a plate is
104                   significant: the vertices must be ordered in the
105                   positive (counterclockwise) sense with respect to
106                   the outward normal direction associated with the
107                   plate. In other words, if V1, V2, V3 are the
108                   vertices of a plate, then
109 
110                      ( V2 - V1 )  x  ( V3 - V2 )
111 
112                   points in the outward normal direction. Here
113                   "x" denotes the vector cross product operator.
114 
115 
116 -Detailed_Output
117 
118    The function returns the total area of the input set of plates.
119    Each plate contributes the area of the triangle defined by the
120    plate's vertices.
121 
122    If the components of the vertex array have length unit L, then the
123    output area has units
124 
125        2
126       L
127 
128 -Parameters
129 
130    None.
131 
132 -Exceptions
133 
134    1) If the number of plates is less than 0, the error
135       SPICE(BADPLATECOUNT) is signaled.
136 
137    2) If the number of plates is positive and the number of vertices
138       is less than 3, the error SPICE(TOOFEWVERTICES) is signaled.
139 
140    3) If any plate contains a vertex index outside of the range
141 
142          [1, nv]
143 
144       the error SPICE(INDEXOUTOFRANGE) will be signaled.
145 
146 -Files
147 
148    None.
149 
150 -Particulars
151 
152    This routine computes the total area of a set of triangular
153    plates. The plates need not define a closed surface.
154 
155    Examples of valid plate sets:
156 
157       Tetrahedron
158       Box
159       Tiled ellipsoid
160       Tiled ellipsoid with one plate removed
161       Two disjoint boxes
162       Two boxes with intersection having positive volume
163       Single plate
164       Empty plate set
165 
166 
167 -Examples
168 
169    The numerical results shown for these examples may differ across
170    platforms. The results depend on the SPICE kernels used as input
171    (if any), the compiler and supporting libraries, and the machine
172    specific arithmetic implementation.
173 
174 
175    1) Compute the area of the pyramid defined by the four
176       triangular plates whose vertices are the 3-element
177       subsets of the set of vectors
178 
179          ( 0, 0, 0 )
180          ( 1, 0, 0 )
181          ( 0, 1, 0 )
182          ( 0, 0, 1 )
183 
184 
185    Example code begins here.
186 
187 
188       /.
189       PROGRAM EX1
190       ./
191 
192       /.
193       Compute the area of a plate model representing the pyramid
194       with one vertex at the origin and the other vertices
195       coinciding with the standard basis vectors.
196       ./
197 
198       #include <stdio.h>
199       #include "SpiceUsr.h"
200 
201       int main()
202       {
203          /.
204          Local constants
205          ./
206          #define NVERT           4
207          #define NPLATE          4
208 
209          /.
210          Local variables
211          ./
212          SpiceDouble             area;
213 
214          /.
215          Let the notation
216 
217             < A, B >
218 
219          denote the dot product of vectors A and B.
220 
221          The plates defined below lie in the following planes,
222          respectively:
223 
224             Plate 1:    { P :  < P, (-1,  0,  0) > = 0 }
225             Plate 2:    { P :  < P, ( 0, -1,  0) > = 0 }
226             Plate 3:    { P :  < P, ( 0,  0, -1) > = 0 }
227             Plate 4:    { P :  < P, ( 1,  1,  1) > = 1 }
228 
229          ./
230          SpiceDouble             vrtces[NVERT ][3] =
231 
232                                  { { 0.0, 0.0, 0.0 },
233                                    { 1.0, 0.0, 0.0 },
234                                    { 0.0, 1.0, 0.0 },
235                                    { 0.0, 0.0, 1.0 }  };
236 
237          SpiceInt                plates[NPLATE][3] =
238 
239                                  { { 1, 4, 3 },
240                                    { 1, 2, 4 },
241                                    { 1, 3, 2 },
242                                    { 2, 3, 4 }  };
243 
244          area = pltar_c( NVERT, vrtces, NPLATE, plates );
245 
246          printf ( "Expected area  =    (3 + sqrt(3)) / 2\n"
247                   "               =    0.23660254037844384e+01\n" );
248          printf ( "Computed area  =   %24.17e\n", area            );
249 
250          return ( 0 );
251       }
252 
253 
254    When this program was executed on a PC/Linux/gcc/64-bit platform,
255    the output was:
256 
257 
258       Expected area   =    (3 + SQRT(3)) / 2
259                       =    0.23660254037844384E+01
260       Computed area   =    2.3660254037844384
261 
262 
263 -Restrictions
264 
265    None.
266 
267 -Literature_References
268 
269    None.
270 
271 -Author_and_Institution
272 
273    N.J. Bachman    (JPL)
274 
275 -Version
276 
277    -CSPICE Version 1.0.0, 24-OCT-2016 (NJB)
278 
279 -Index_Entries
280 
281    compute plate model area
282 
283 -&
284 */
285 
286 { /* Begin pltar_c */
287 
288 
289 
290    /*
291    Local variables
292    */
293    SpiceDouble             retval;
294 
295 
296    /*
297    Participate in error tracing.
298    */
299    chkin_c ( "pltar_c" );
300 
301 
302    retval = (SpiceDouble) pltar_ ( ( integer    * ) &nv,
303                                    ( doublereal * ) vrtces,
304                                    ( integer    * ) &np,
305                                    ( integer    * ) plates  );
306    chkout_c ( "pltar_c" );
307 
308    return ( retval );
309 
310 
311 } /* End pltar_c */
312