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: s2501.c,v 1.11 2001-06-12 11:07:33 jbt Exp $
45  *
46  */
47 
48 
49 #define S2501
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s2501(SISLSurf * surf,int ider,double derive[],double normal[],double * gaussian,int * jstat)55 s2501(SISLSurf *surf, int ider, double derive[], double normal[],
56       double *gaussian, int *jstat)
57 #else
58  void s2501(surf, ider, derive, normal, gaussian, jstat)
59       SISLSurf *surf;
60       int ider;
61       double derive[];
62       double normal[];
63       double *gaussian;
64       int *jstat;
65 #endif
66 /*
67 ***************************************************************************
68 *
69 ***************************************************************************
70 *  PURPOSE      :  To compute the Gaussian K(u,v) of a Surface for given
71 *                  values (u,v). This is a lower level routine, used
72 *                  for evaluation of many K(u,v)'s.
73 *  INPUT        :
74 *          surf     - Pointer to the surface to evaluate.
75 *          ider     - Only implemented for ider=0 (derivative order).
76 *       derive      - Array containing derivatives from routine s1421().
77 *                     Size = idim*6.
78 *       normal      - Array containing the normal from routine s1421().
79 *                     Size = 3.
80 *
81 *  OUTPUT       :
82 *     gaussian      - Gaussian of the surface in (u,v) =
83 *        jstat      - Status messages
84 *
85 *                         = 0 : Ok.
86 *                         < 0 : Error.
87 *
88 *  METHOD       :  The Gaussian is given by
89 *
90 *                      K(x,y) = (hxx*hyy-hxy^2)/((1+hx^2+hy^2)^2),
91 *
92 *                  if the surface (h(x,y)) is 1D, and
93 *
94 *                      K(u,v) = (eg-f*f)/(EG-F*F),
95 *
96 *                  if the surface (X(u,v)) is 3D. The variables E,F,G,e,f and g
97 *                  are the coefficients of the first and second fundamental form.
98 *                  They are given by: e = <N,Xuu>, f = <N,Xuv>, g = <N,Xvv>,
99 *                  E = <Xu,Xu>, F = <Xu,Xv> and G = <Xv,Xv>.
100 *
101 *  REFERENCES   :  Differential Geometry of Curves and Surfaces,
102 *                    (Manfredo P. Do Carmo, Prentice Hall,
103 *                      ISBN: 0-13-212589-7).
104 *-
105 *  CALLS        :
106 *
107 *  LIMITATIONS  :
108 *                (i) If the surface is degenerated (not regular) at the point
109 *                    (u,v), it makes no sense to speak about the Gaussian
110 *                    K(u,v).
111 *               (ii) If the surface is closed to degenerate, the Gaussian
112 *                    K(u,v) can be numerical unstable.
113 *              (iii) The surface is Cr the Gaussian calculated is C(r-2).
114 *                    To get the correct behavior use the sided evaluator s1422
115 *		     instead of s1421.
116 *               (iv) The dimension of the space in which the surface lies must
117 *                    be 1,2 or 3, if not, jstat = -105 is returned.
118 *
119 *
120 * WRITTEN BY   :  Geir Westgaard, SINTEF, Oslo, Norway.            Date: 1995-1
121 * CORRECTED BY :  Ulf J Krystad, SINTEF, Oslo, Norway.             Date: 1995-1
122 *                 Removed knot navigators + some clean up.
123 * CORRECTED BY :  Johannes Kaasa, SINTEF, Oslo, Norway.            Date: 1995-8
124 *                 Calculated the fundamental form coefficients by
125 *                 calls to s2513.
126 *****************************************************************************
127 */
128 {
129    double fundform[6]; /* The coefficients of the fundamental forms.
130 			  The sequence is: E, F, G, e, f, g.         */
131 
132    if (ider != 0) goto err178;
133 
134    if (surf->idim == 1 || surf->idim == 3) /* 1D and 3D surface */
135    {
136       s2513(surf, ider, 2, 0, derive, normal, fundform, jstat);
137       if (*jstat < 0) goto error;
138 
139       *gaussian = (fundform[3]*fundform[5]-fundform[4]*fundform[4])
140 	 /((fundform[0]*fundform[2] - fundform[1]*fundform[1])*
141 	   (fundform[0]*fundform[2] - fundform[1]*fundform[1]));
142   }
143 
144   else if (surf->idim == 2) /* 2D surface */
145   {
146     /* The surface lies in a plane => K(u,v) = 0 */
147 
148     *gaussian = 0.0;
149   }
150   else /* When surf->idim != 1,2 or 3 */
151   {
152     goto err105;
153   }
154 
155   /* Successful computations  */
156 
157   *jstat = 0;
158   goto out;
159 
160 
161    /* Error in input, surf->idim != 1,2 or 3 */
162 err105:
163   *jstat = -105;
164   s6err("s2501",*jstat,0);
165   goto out;
166 
167   /* Illegal derivative requested. */
168 err178:
169   *jstat = -178;
170   s6err("s2501",*jstat,0);
171   goto out;
172 
173 error:
174   s6err("s2501",*jstat,0);
175   goto out;
176 
177 out:
178 
179   return;
180 
181 }
182