POLYNOMIALCURVEFIT Fit a polynomial curve to a series of points.

   [XC YC] = polynomialCurveFit(T, XT, YT, ORDER)
   T is a Nx1 vector
   XT and YT are coordinate for each parameter value (column vectors)
   ORDER is the degree of the polynomial used for interpolation
   XC and YC are polynomial coefficients, given in ORDER+1 row vectors,
   starting from degree 0 and up to degree ORDER.

	[XC YC] = polynomialCurveFit(T, POINTS, ORDER);
   specifies coordinate of points in a Nx2 array.

   Example:
   N = 50;
   t = linspace(0, 3*pi/4, N)';
   xp = cos(t); yp = sin(t);
   [xc yc] = polynomialCurveFit(t, xp, yp, 3);
   curve = polynomialCurvePoint(t, xc, yc);
   drawCurve(curve);


	[XC YC] = polynomialCurveFit(..., T_I, COND_I);
   Impose some specific conditions. T_I is a value of the parametrization
   variable. COND_I is a cell array, with 2 columns, and as many rows as
   the derivatives specified for the given T_I. Format for COND_I is:
   COND_I = {X_I, Y_I; X_I', Y_I'; X_I", Y_I"; ...};
   with X_I and Y_I being the imposed coordinate at position T_I, X_I' and
   Y_I' being the imposed first derivatives, X_I" and Y_I" the imposed
   second derivatives, and so on...
   To specify a derivative without specifying derivative with lower
   degree, value of lower derivative can be let empty, using '[]'

   Example:
   % defines a curve (circle arc) with small perturbations
   N = 100;
   t = linspace(0, 3*pi/4, N)';
   xp = cos(t)+.1*randn(size(t)); yp = sin(t)+.1*randn(size(t));
   
   % plot the points
   figure(1); clf; hold on;
   axis([-1.2 1.2 -.2 1.2]); axis equal;
   drawPoint(xp, yp);

   % fit without knowledge on bounds
   [xc0 yc0] = polynomialCurveFit(t, xp, yp, 5);
   curve0 = polynomialCurvePoint(t, xc0, yc0);
   drawCurve(curve0);

   % fit by imposing coordinate on first point
   [xc1 yc1] = polynomialCurveFit(t, xp, yp, 5, 0, {1, 0});
   curve1 = polynomialCurvePoint(t, xc1, yc1);
   drawCurve(curve1, 'r');

   % fit by imposing coordinate (1,0) and derivative (0,1) on first point
   [xc2 yc2] = polynomialCurveFit(t, xp, yp, 5, 0, {1, 0;0 1});
   curve2 = polynomialCurvePoint(t, xc2, yc2);
   drawCurve(curve2, 'g');

   % fit by imposing several conditions on various points
   [xc3 yc3] = polynomialCurveFit(t, xp, yp, 5, ...
       0, {1, 0;0 1}, ...      % coord and first derivative of first point
       3*pi/4, {-sqrt(2)/2, sqrt(2)/2}, ...    % coord of last point
       pi/2, {[], [];-1, 0});      % derivative of point on the top of arc
   curve3 = polynomialCurvePoint(t, xc3, yc3);
   drawCurve(curve3, 'k');

   Requires the optimization Toolbox.


   Examples:
   polynomialCurveFit

   See also
   polynomialCurves2d

 ------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 Created: 2007-02-27
 Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.

Package: matgeom