1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, Department of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is part of SISL.
11  *
12  * SISL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * SISL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with SISL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using SISL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the SISL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #include "sisl-copyright.h"
41 
42 /*
43  *
44  * $Id: s2514.c,v 1.3 2001-06-12 11:07:34 jbt Exp $
45  *
46  */
47 
48 
49 #define S2514
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s2514(SISLSurf * surf,int ider,double derive[],double normal[],double gaussian[],int * stat)55    s2514(SISLSurf *surf, int ider, double derive[], double normal[],
56       double gaussian[], int *stat)
57 #else
58  void s2514(surf, ider, derive, normal, gaussian, stat)
59       SISLSurf *surf;
60       int ider;
61       double derive[];
62       double normal[];
63       double gaussian[];
64       int *stat;
65 #endif
66 /*
67 ***************************************************************************
68 *
69 ***************************************************************************
70 *  PURPOSE      :  To compute the numerator and denominator of the Gaussian
71 *                  K(u,v) of a Surface for given
72 *                  values (u,v). This is a lower level routine, used
73 *                  for evaluation of many K(u,v)'s.
74 *  INPUT        :
75 *          surf     - Pointer to the surface to evaluate.
76 *          ider     - Only implemented for ider=0 (derivative order).
77 *       derive      - Array containing derivatives from routine s1421().
78 *                     Size = idim*6.
79 *       normal      - Array containing the normal from routine s1421().
80 *                     Size = 3.
81 *
82 *  OUTPUT       :
83 *     gaussian      - The nominator and denominator of the Gaussian for the
84 *                     surface in (parvalue[0],parvalue[1]).
85 *                     Size = 2.
86 *        stat       - Status messages
87 *
88 *                         = 0 : Ok.
89 *                         < 0 : Error.
90 *
91 *  METHOD       :  The Gaussian is given by
92 *
93 *                      K(x,y) = (hxx*hyy-hxy^2)/((1+hx^2+hy^2)^2),
94 *
95 *                  if the surface (h(x,y)) is 1D, and
96 *
97 *                      K(u,v) = (eg-f*f)/(EG-F*F),
98 *
99 *                  if the surface (X(u,v)) is 3D. The variables E,F,G,e,f and g
100 *                  are the coefficients of the first and second fundamental form.
101 *                  They are given by: e = <N,Xuu>, f = <N,Xuv>, g = <N,Xvv>,
102 *                  E = <Xu,Xu>, F = <Xu,Xv> and G = <Xv,Xv>.
103 *
104 *  REFERENCES   :  Differential Geometry of Curves and Surfaces,
105 *                    (Manfredo P. Do Carmo, Prentice Hall,
106 *                      ISBN: 0-13-212589-7).
107 *-
108 *  CALLS        :
109 *
110 *  LIMITATIONS  :
111 *                (i) If the surface is degenerated (not regular) at the point
112 *                    (u,v), it makes no sense to speak about the Gaussian
113 *                    K(u,v).
114 *               (ii) If the surface is closed to degenerate, the Gaussian
115 *                    K(u,v) can be numerical unstable.
116 *              (iii) The surface is Cr the Gaussian calculated is C(r-2).
117 *                    To get the correct behavior use the sided evaluator s1422
118 *		     instead of s1421.
119 *               (iv) The dimension of the space in which the surface lies must
120 *                    be 1,2 or 3, if not, stat = -105 is returned.
121 *
122 *
123 * WRITTEN BY   :  Johannes Kaasa, SINTEF, Oslo, Norway.            Date: 1995-8
124 *****************************************************************************
125 */
126 {
127    double fundform[6]; /* The coefficients of the fundamental forms.
128 			  The sequence is: E, F, G, e, f, g.         */
129 
130    if (ider != 0) goto err178;
131 
132    if (surf->idim == 1 || surf->idim == 3) /* 1D and 3D surface */
133    {
134       s2513(surf, ider, 2, 0, derive, normal, fundform, stat);
135       if (*stat < 0) goto error;
136 
137       gaussian[0] = fundform[3]*fundform[5]-fundform[4]*fundform[4];
138       gaussian[1] = (fundform[0]*fundform[2] - fundform[1]*fundform[1])*
139 	   (fundform[0]*fundform[2] - fundform[1]*fundform[1]);
140   }
141 
142   else if (surf->idim == 2) /* 2D surface */
143   {
144     /* The surface lies in a plane => K(u,v) = 0 */
145 
146     gaussian[0] = 0.0;
147     gaussian[1] = 1.0;
148   }
149   else /* When surf->idim != 1,2 or 3 */
150   {
151     goto err105;
152   }
153 
154   /* Successful computations  */
155 
156   *stat = 0;
157   goto out;
158 
159 
160    /* Error in input, surf->idim != 1,2 or 3 */
161 err105:
162   *stat = -105;
163   s6err("s2514",*stat,0);
164   goto out;
165 
166   /* Illegal derivative requested. */
167 err178:
168   *stat = -178;
169   s6err("s2514",*stat,0);
170   goto out;
171 
172 error:
173   s6err("s2514",*stat,0);
174   goto out;
175 
176 out:
177 
178   return;
179 
180 }
181