home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vopl / glvopl.lha / glvopl / src / cubicsp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-10  |  1020 b   |  63 lines

  1. #include "vopl.h"
  2.  
  3. /*
  4.  *     cubicsp
  5.  *
  6.  *    Fit cubic splines using Cardinal splines and vogl "crv" routine
  7.  */
  8. cubicsp(x, y, n)
  9.     float *x, *y;
  10.     int    n;
  11. {
  12.     float    geom[4][3], x0, y0, xnp1, ynp1;
  13.     int    i, j;
  14.  
  15.     /*
  16.      *  Make fake end points
  17.      */
  18.     x0 = 2.0 * WhatX(x[0]) - WhatX(x[1]);
  19.     y0 = 2.0 * WhatY(y[0]) - WhatY(y[1]);
  20.     xnp1 = 2.0 * WhatX(x[n-1]) - WhatX(x[n-2]);
  21.     ynp1 = 2.0 * WhatY(y[n-1]) - WhatY(y[n-2]);
  22.  
  23.     /*
  24.      *  Do first segment
  25.      */
  26.     for (i = 0; i < 3; i++)
  27.         for (j = 0; j < 4; j++)
  28.             geom[j][i] = 0.0;
  29.  
  30.     geom[0][0] = x0;
  31.     geom[0][1] = y0;
  32.     for (i = 1; i < 4; i++) {
  33.         geom[i][0] = WhatX(x[i-1]);
  34.         geom[i][1] = WhatY(y[i-1]);
  35.     }
  36.  
  37.     crv(geom);
  38.  
  39.     /*
  40.          * In between curve segments
  41.      */
  42.     for (j = 0; j < n-3; j++) {
  43.         for (i = 0; i < 4; i++) {
  44.             geom[i][0] = WhatX(x[i+j]);
  45.             geom[i][1] = WhatY(y[i+j]);
  46.         }
  47.  
  48.         crv(geom);
  49.     }
  50.  
  51.     /*
  52.           *  Last segment
  53.      */
  54.     for (i = 0; i < 3; i++) {
  55.         geom[i][0] = WhatX(x[n+i-3]);
  56.         geom[i][1] = WhatY(y[n+i-3]);
  57.     }
  58.  
  59.     geom[3][0] = xnp1;
  60.     geom[3][1] = ynp1;
  61.     crv(geom);
  62. }
  63.