<commit_before>/*****************************************************************************/
/*                                                                           */
/*                                                                           */
/* (c) Copyright 1995 by                                                     */
/*     SINTEF, Oslo, Norway                                                  */
/*     All rights reserved. See the copyright.h for more details.            */
/*                                                                           */
/*****************************************************************************/

#include "copyright.h"

/*
 *
 * $Id: s2507.c,v 1.6 1995-06-29 12:08:07 jka Exp $
 *
 */


#define S2507

#include "sislP.h"

#if defined(SISLNEEDPROTOTYPES)
void
s2507(SISLSurf *surf, int ider, double derive[], double normal[],
      double *totalCurvature, int *jstat)
#else
 void s2507(surf, ider, derive, normal, totalCurvature, jstat)
      SISLSurf *surf;
      int ider;
      double derive[],
      double normal[],
      double *totalCurvature;
      int *jstat;
#endif
/*
***************************************************************************
*
***************************************************************************
*  PURPOSE      :  To compute the total curvature T(u,v) of a Surface
*                  for given values (u,v). This is a lower level routine,
*                  used for evaluation of many T(u,v)'s.
*
*  INPUT        :
*          surf     - Pointer to the surface to evaluate.
*          ider     - Not used.
*       derive      - Array containing derivatives from routine s1421().
*                     Size = idim*6.
*       normal      - Array containing the normal from routine s1421().
*                     Size = 3.
*
*  INPUT/OUTPUT :
*
*  OUTPUT       :
*    totalCurvature - Total curvature of the surface in (u,v).
*        jstat      - Staus messages
*                         = 0 : Ok.
*                         < 0 : Error.
*
*  METHOD        :  The total curvature is given by
*
*                      T(x,y) = k1^2 + k2^2,
*
*                  if the surface (h(x,y)) is 1D, and
*
*                      T(u,v) = = k1^2 + k2^2,
*
*                  if the surface (X(u,v)) is 3D. The variables E,F,G,e,f and g
*                  are the coefficients of the first and second fundamental form.
*                  They are given by: e = <N,Xuu>, f = <N,Xuv>, g = <N,Xvv>,
*                  E = <Xu,Xu>, F = <Xu,Xv> and G = <Xv,Xv>.
*
*  REFERENCES   :  Differential Geometry of Curves and Surfaces,
*                    (<NAME>, Prentice Hall,
*                      ISBN: 0-13-212589-7).
*-
*  CALLS        :
*
*  LIMITATIONS  :
*                (i) If the surface is degenerated (not regular) at the point
*                    (u,v), it makes now sense to speak about T(u,v).
*               (ii) If the surface is closed to degenerate, T(u,v)
*                    can be numerical unstable.
*              (iii) The surface should be C2, since the total c. is calculated
*                    from the second derivatives.
*               (iv) The dimension of the space in which the surface lies must
*                    be 1,2 or 3.  The routine return jstat < 0.
*
*
* WRITTEN BY :  <NAME>, SINTEF, Oslo, Norway.            Date: 1995-1
* CORRECTED BY :  <NAME>, SINTEF, Oslo, Norway.          Date: 1995-06
*                 Error in explicit curvature.
* CORRECTED BY :  <NAME>, SINTEF, Oslo, Norway.          Date: 1995-06
*                 Used absolute valute in square for principal curvature.
*****************************************************************************
*/
{
  double a,b;             /* Dummy variables.                                */
  double hx,hy,
    hxx,hyy,hxy;         /* The derivatives of the 1D surface, h(x,y).      */
  double E,F,G;           /* The coefficents of the first fundamental form,
			     that is, E = <Xu,Xu>, F = <Xu,Xv>  and
			     G = <Xv,Xv>.                                    */
  double e,f,g;           /* The coefficents of the second fundamental form,
			     that is, e = <N,Xuu>, f = <N,Xuv> and
			     g = <N,Xvv>.                                    */
  double gc;              /* Gaussian curvature.                             */
  double mc;              /* Mean curvature.                                 */
  double k1,k2;           /* Max. and min. principal curvature.              */



  if (surf->idim == 1) /* 1D surface */
  {
    hx  = derive[1];
    hy  = derive[2];
    hxx = derive[3];
    hxy = derive[4];
    hyy = derive[5];


    a = (1+hx*hx+hy*hy);
    gc = (hxx*hyy-hxy*hxy)/(a*a);

    b = sqrt(a*a*a);

    a = (1.0 + hx*hx)*hyy - 2.0*hx*hy*hxy + (1.0 + hy*hy)*hxx;

    mc = 0.5*a/b;

    a = sqrt(fabs(mc*mc - gc));
    k1 = mc + a;
    k2 = mc - a;

    *totalCurvature = k1*k1 + k2*k2;
  }

  else if (surf->idim == 2) /* 2D surface */
  {
    /* The surface lies in a plane => T(u,v) = 0 */

    *totalCurvature = 0.0;
  }
  else if (surf->idim == 3) /* 3D surface */
  {
    /* E = <Xu,Xu> */
    E = derive[3]*derive[3]+derive[4]*derive[4]+derive[5]*derive[5];

	 /* F = <Xu,Xv> */
    F = derive[3]*derive[6]+derive[4]*derive[7]+derive[5]*derive[8];

    /* G = <Xv,Xv> */
    G = derive[6]*derive[6]+derive[7]*derive[7]+derive[8]*derive[8];

    /* b = EG + F^2. */
    b = E*G-F*F;

    /* e = <N,Xuu> (/ sqrt(E*G-F*F)) */
    e = normal[0]*derive[9]+normal[1]*derive[10]+normal[2]*derive[11];

    /* f = <N,Xuv> (/ sqrt(E*G-F*F)) */
    f = normal[0]*derive[12]+normal[1]*derive[13]+normal[2]*derive[14];

    /* g = <N,Xvv> (/ sqrt(E*G-F*F)) */
    g = normal[0]*derive[15]+normal[1]*derive[16]+normal[2]*derive[17];

    /* Compute total curvature = k1^2 + k2^2. */

    gc = (e*g-f*f)/(b*b);

    a = 0.5*(e*G - 2.0*f*F + g*E);
    b = b*sqrt(b);

    mc = a/b;

    a = sqrt(fabs(mc*mc - gc));
    k1 = mc + a;
    k2 = mc - a;

    *totalCurvature = k1*k1 + k2*k2;

  }
  else /* When surf->idim != 1,2 or 3 */
  {
    goto err105;
  }




  /* Successful computations  */

  *jstat = 0;
  goto out;


   /* Error in input, surf->idim != 1,2 or 3 */
err105:
  *jstat = -105;
  s6err("s2507", *jstat, 0);
  goto out;

out:

  return;

}
<commit_msg>no entry<commit_after>/*****************************************************************************/
/*                                                                           */
/*                                                                           */
/* (c) Copyright 1995 by                                                     */
/*     SINTEF, Oslo, Norway                                                  */
/*     All rights reserved. See the copyright.h for more details.            */
/*                                                                           */
/*****************************************************************************/

#include "copyright.h"

/*
 *
 * $Id: s2507.c,v 1.7 1995-08-01 10:47:46 jka Exp $
 *
 */


#define S2507

#include "sislP.h"

#if defined(SISLNEEDPROTOTYPES)
void
s2507(SISLSurf *surf, int ider, double derive[], double normal[],
      double *totalCurvature, int *jstat)
#else
 void s2507(surf, ider, derive, normal, totalCurvature, jstat)
      SISLSurf *surf;
      int ider;
      double derive[],
      double normal[],
      double *totalCurvature;
      int *jstat;
#endif
/*
***************************************************************************
*
***************************************************************************
*  PURPOSE      :  To compute the total curvature T(u,v) of a Surface
*                  for given values (u,v). This is a lower level routine,
*                  used for evaluation of many T(u,v)'s.
*
*  INPUT        :
*          surf     - Pointer to the surface to evaluate.
*          ider     - Not used.
*       derive      - Array containing derivatives from routine s1421().
*                     Size = idim*6.
*       normal      - Array containing the normal from routine s1421().
*                     Size = 3.
*
*  INPUT/OUTPUT :
*
*  OUTPUT       :
*    totalCurvature - Total curvature of the surface in (u,v).
*        jstat      - Staus messages
*                         = 0 : Ok.
*                         < 0 : Error.
*
*  METHOD        :  The total curvature is given by
*
*                      T(x,y) = k1^2 + k2^2,
*
*                  if the surface (h(x,y)) is 1D, and
*
*                      T(u,v) = = k1^2 + k2^2,
*
*                  if the surface (X(u,v)) is 3D. The variables E,F,G,e,f and g
*                  are the coefficients of the first and second fundamental form.
*                  They are given by: e = <N,Xuu>, f = <N,Xuv>, g = <N,Xvv>,
*                  E = <Xu,Xu>, F = <Xu,Xv> and G = <Xv,Xv>.
*
*  REFERENCES   :  Differential Geometry of Curves and Surfaces,
*                    (<NAME>, Prentice Hall,
*                      ISBN: 0-13-212589-7).
*-
*  CALLS        :
*
*  LIMITATIONS  :
*                (i) If the surface is degenerated (not regular) at the point
*                    (u,v), it makes now sense to speak about T(u,v).
*               (ii) If the surface is closed to degenerate, T(u,v)
*                    can be numerical unstable.
*              (iii) The surface should be C2, since the total c. is calculated
*                    from the second derivatives.
*               (iv) The dimension of the space in which the surface lies must
*                    be 1,2 or 3.  The routine return jstat < 0.
*
*
* WRITTEN BY :  <NAME>, SINTEF, Oslo, Norway.            Date: 1995-1
* CORRECTED BY :  <NAME>, SINTEF, Oslo, Norway.          Date: 1995-06
*                 Used absolute valute in square for principal curvature.
* CORRECTED BY :  <NAME>, SINTEF, Oslo, Norway.            Date: 1995-8
*                 Calculated the fundamental form coefficients by
*                 calls to s2513.
*****************************************************************************
*/
{
   double fundform[6]; /* The coefficients of the fundamental forms.
			  The sequence is: E, F, G, e, f, g.              */
   double gc;          /* Gaussian curvature.                             */
   double mc;          /* Mean curvature.                                 */
   double k1,k2;       /* Max. and min. principal curvature.              */



   if (surf->idim == 1 || surf->idim == 3) /* 1D and 3D surface */
   {
      s2513(surf, ider, 0, derive, normal, fundform, jstat);
      if (*jstat < 0) goto error;
      
      gc = (fundform[3]*fundform[5]-fundform[4]*fundform[4])
	 /((fundform[0]*fundform[2] - fundform[1]*fundform[1])*
	   (fundform[0]*fundform[2] - fundform[1]*fundform[1]));
      mc = 0.5*(fundform[3]*fundform[2] - 2*fundform[4]*fundform[1] 
			    + fundform[5]*fundform[0])
	 /((fundform[0]*fundform[2] - fundform[1]*fundform[1])
	   *sqrt(fundform[0]*fundform[2] - fundform[1]*fundform[1]));

     k1 = mc + sqrt(fabs(mc*mc - gc));
     k2 = mc - sqrt(fabs(mc*mc - gc));

     *totalCurvature = k1*k1 + k2*k2;
   }
  else if (surf->idim == 2) /* 2D surface */
  {
    /* The surface lies in a plane => T(u,v) = 0 */

    *totalCurvature = 0.0;
  }
  else /* When surf->idim != 1,2 or 3 */
  {
    goto err105;
  }

  /* Successful computations  */

  *jstat = 0;
  goto out;


   /* Error in input, surf->idim != 1,2 or 3 */
err105:
  *jstat = -105;
  s6err("s2507", *jstat, 0);
  goto out;
  
error:
  s6err("s2507",*jstat,0);
  goto out;

out:

  return;

}

{'fraction_non_alphanumeric': 0.1972075275344723, 'fraction_numerical': 0.03269447576099211, 'mean_word_length': 1.5746818486269256, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3334988', 'n_tokens_mistral': 3987, 'n_tokens_neox': 3621, 'n_words': 987}