Previous: fitbs2 Up: ../plot79_f.html Next: fitbv


FITBS3

       SUBROUTINE  FITBS3 (XFIT, YFIT, ZFIT, NFIT, MAXFIT, X, Y, Z, N,
      X     K1, KN, NEXTRA)
 C$    (B-Spline 3-D)
 C$    Make a cubic B-spline fit to  a set of 3-D control  points.
 C$    The points  may be  positioned  arbitrarily, and  need  not
 C$    correspond to a single-valued  function.  A B-spline  curve
 C$    does not  normally pass  through the  original points,  but
 C$    will  form  a  smooth  approximation  along  their  general
 C$    direction.  B-splines have  several interesting and  useful
 C$    properties:
 C$
 C$         The  curve  along   any  four  consecutive   line
 C$         segments will  always  lie  inside  their  convex
 C$         hull.  This means that if four consecutive points
 C$         are colinear, the  curve between  the second  and
 C$         third points will be a straight line.
 C$
 C$         The curve starts  at the  point (P(1)  + 4P(2)  +
 C$         P(3))/6 and ends at the point (P(N-2) + 4P(N-1) +
 C$         P(N))/6, where P(K) is the K-th point.  Thus,  if
 C$         the first three points  are identical, the  curve
 C$         can be made to start  at them, and similarly  for
 C$         the last three.
 C$
 C$         The curve passes  close to the  midpoint of  each
 C$         side of the polygon formed by the control points,
 C$         with the exception of the first and the last.
 C$
 C$         The curve passes through a point one-third of the
 C$         way along  the  straight line  joining  the  K-th
 C$         point to the mid-point of the line joining points
 C$         K-1 and K+1.
 C$
 C$         The B-spline fit is a local one, and a change  in
 C$         the K-th control point will affect the curve only
 C$         along the  four line  segments K-2..K-1,  K-1..K,
 C$         K..K+1, and  K+1..K+2.  This  is the  reason  for
 C$         terming the original data point "control" points.
 C$
 C$         A cubic  B-spline is  continuous in  its  zeroth,
 C$         first  and  second  derivatives  if  the  control
 C$         points are  distinct.   If two  adjacent  control
 C$         points are  identical, its  second derivative  is
 C$         discontinuous  at  that   point;  if  three   are
 C$         identical,   its   first   derivative   is   also
 C$         discontinuous; if four  are identical, the  curve
 C$         itself is discontinuous.
 C$
 C$         A B-spline  curve  generated  for  N  consecutive
 C$         points is the  same as that  for the same  points
 C$         taken in reverse order.
 C$
 C$    The B-spline is  thus an exceedingly  useful tool in  curve
 C$    design,  since  simple   experimentation  with   individual
 C$    control points  can be  used to  obtain any  desired  curve
 C$    shape.  It has the additional advantage that it generalizes
 C$    easily to 3-D and 4-D space curves.
 C$
 C$    The output arguments are:
 C$
 C$    XFIT(*),
 C$    YFIT(*),
 C$    ZFIT(*)........Output data points.
 C$    NFIT...........Number   of   points  actually   stored   in
 C$                   XFIT(*),  YFIT(*),  and  ZFIT(*)  (will  not
 C$                   exceed  MAXFIT).    The   points   will   be
 C$                   distributed at  intervals  of  approximately
 C$                   equal arc length along the curve.
 C$
 C$    The input arguments are:
 C$
 C$    MAXFIT.........Limit on number of points desired in XFIT(*)
 C$                   and YFIT(*).
 C$    X(*),
 C$    Y(*),
 C$    Z(*)...........Original data points.
 C$    N..............Number of original data points.
 C$    K1.............Number  of times  to implicitly  repeat  the
 C$                   first original data  point.  If  out of  the
 C$                   range 0..3, the  nearer of  0 or  3 will  be
 C$                   used.  Setting K1 = 2  can be used to  force
 C$                   the curve to start at the first point.
 C$    KN.............Number  of times  to  implicitly  repeat the
 C$                   last original data  point (point  N+NEXTRA).
 C$                   If out of the range 0..3, the nearer of 0 or
 C$                   3 will be used.  Setting KN = 2 can be  used
 C$                   to force  the curve  to  start at  the  last
 C$                   point.
 C$    NEXTRA......... .LE. 0 - Use exactly N data points.
 C$                    .GT. 0 - Use N+NEXTRA data points, wrapping
 C$                             around in the  arrays X(*),  Y(*),
 C$                             and Z(*),  so  that  position  N+K
 C$                             indexes the  array at  position  K
 C$                             (actually at mod(N+K-1,N)+1).
 C$                   If NEXTRA  is out  of  the range  0..N,  the
 C$                   nearer of 0 or N will be used.
 C$
 C$    If the first three points are  the same as the last  three,
 C$    the B-spline curve will be  a continuous closed curve.   If
 C$    the data points form a  convex polygon, the B-spline  curve
 C$    will also be convex, and lie entirely inside the data point
 C$    polygon.  Thus, given a set  of points defining a  polygon,
 C$    where the last  is implicitly  connected to  the first,  by
 C$    setting NEXTRA = 3, one can generate a fit which itself  is
 C$    a polygon.   For example,  the  four points  (0,0),  (1,0),
 C$    (1,1), and (0,1)  with NEXTRA  = 3 will  generate a  smooth
 C$    curve which is almost a circle.
 C$    (13-MAR-82)