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


FITBZ2

       SUBROUTINE  FITBZ2 (XFIT, YFIT, NFIT, MAXFIT, X, Y, N, K1, KN, 
      X     NEXTRA)
 C$    (Bezier 2-D)
 C$    Make an (N-1)-order Bezier  fit to a set  of N 2-D  control
 C$    points.  The points may be positioned arbitrarily, and need
 C$    not correspond to a single-valued function.  A Bezier curve
 C$    does not  normally pass  through the  original points,  but
 C$    will  form  a  smooth  approximation  along  their  general
 C$    direction.  Bezier  curves  have  several  interesting  and
 C$    useful properties:
 C$
 C$         Although the fit is of high polynomial degree for
 C$         large numbers of control points, the Bezier curve
 C$         does not exhibit the oscillations  characteristic
 C$         of ordinary polynomial fits.
 C$
 C$         If  the   control   points  are   distinct,   the
 C$         derivatives of orders 0..N-1 are continuous.
 C$
 C$         The Bezier curve passes exactly through the first
 C$         and last points, and  at those points is  tangent
 C$         to the adjacent  line segment.   In general,  the
 C$         k-th derivative at  the end  points depends  only
 C$         upon   the   k   adjacent   line   segments,   or
 C$         equivalently,  upon  the  k+1  adjacent   control
 C$         points.
 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$         For four consecutive control points P1..P4, if P2
 C$         = (P1+2Q)/3 and  P3 = (P4+2Q)/3,  then the  curve
 C$         along them is a  parabolic arc with endpoints  at
 C$         P1 and P4 and end tangents intersecting at Q.
 C$
 C$         If   four   consecutive   points   are   (x+r,y),
 C$         (x+r,y+kr), (x+kr,y+r),  and (x,y+r),  where k  =
 C$         4(sqrt(2)-1)/3  (=  0.55228475),  the  curve   is
 C$         almost a circular arc with radius varying between
 C$         r and 1.00027r.
 C$
 C$         For four consecutive  control points  P(1)..P(4),
 C$         provided the distances P(1)..P(2) and  P(3)..P(4)
 C$         do not exceed the distance P(1)..P(4), the Bezier
 C$         curve along them cannot have any loops.
 C$
 C$         A simple formula exists for the area subtended by
 C$         the curve at the origin  (see I.D. Faux and  M.J.
 C$         Pratt,  Computational  Geometry  for  Design  and
 C$         Manufacture, Ellis Horwood Publishers, Chichester
 C$         (1979), p.  151).  This  can be  convenient,  for
 C$         example, in determining the cross-sectional  area
 C$         of a pipe or duct represented by a Bezier  curve.
 C$         
 C$         Although the Bezier fit is a global one, a change
 C$         in the K-th control  point will affect the  curve
 C$         primarily along the four line segments  K-2..K-1,
 C$         K-1..K, K..K+1, and K+1..K+2.  This is the reason
 C$         for terming  the  original data  point  "control"
 C$         points.  The globality of the fit means that  all
 C$         N control points contribute to the curve value at
 C$         any point,  and  the interpolation  is  therefore
 C$         more expensive compared to local methods such  as
 C$         B-spline fits.
 C$    
 C$    The Bezier  curve is  thus an  exceedingly useful  tool  in
 C$    curve 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.  Because of its  global
 C$    nature, it is  not suited for  fitting more to  than a  few
 C$    control points, say about a  dozen.  It is most  frequently
 C$    used with four control points, in which case it is a  cubic
 C$    curve.
 C$
 C$    The output arguments are:
 C$    
 C$    XFIT(*),
 C$    YFIT(*)........Output data points.
 C$    NFIT...........Number of points  actually stored in XFIT(*)
 C$                   and YFIT(*) (will  not exceed MAXFIT).   The
 C$                   points will be  distributed at intervals  of
 C$                   approximately equal  arc  length  along  the
 C$                   curve.
 C$
 C$    The input arguments are:
 C$    
 C$    MAXFIT.........Limit on number of points desired in XFIT(*)
 C$                   and YFIT(*). 
 C$    X(*),Y(*)......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.
 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.
 C$    NEXTRA......... .LE. 0 - Use exactly N data points.
 C$                    .GT. 0 - Use N+NEXTRA data points, wrapping
 C$                             around  in  the  arrays  X(*)  and
 C$                             Y(*), so that position N+K indexes
 C$                             the array at position K  (actually
 C$                             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 Bezier curve will be a continuous closed curve.  If the
 C$    data points form  a convex polygon,  the Bezier curve  will
 C$    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.
 C$    (10-OCT-84)