Previous: fitap Up: ../plot79_f.html Next: fitbs3
SUBROUTINE FITBS2 (XFIT, YFIT, NFIT, MAXFIT, X, Y, N, K1, KN,
X NEXTRA)
C$ (B-Spline 2-D)
C$ Make a cubic B-spline fit to a set of 2-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(*)........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. 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(*) 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 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)