function N = BezierMatrix(n)
  % -----------------------------------------------------------------------
  % BezierMatrix - construct the matrix of combinatorial coefficients, N,
  %                defined as follows.  Write a Bezier curve as
  %                  P(t) = F(t) * G
  %                where
  %                  F = [Jn0 Jn1 ... Jnn]
  %                  G = [B0 B1 ... Bn]'
  %                in which the Jni are the blending functions of order n
  %                and the Bk are the n+1 control points in columns.  For
  %                the sake of efficiency, we want to write F in the form
  %                  F(t) = T * N
  %                where
  %                  T = [t^n t^(n-1) ... t^0]
  %                is a vector of powers of t and N is the matrix of
  %                combinatorial coefficients constructed below.
  %
  % Args: n - the order of the Bezier curve, i.e., n+1 control points
  %
  % Rtns: N - the n+1 x n+1 matrix of combinatorial coefficients
  % -----------------------------------------------------------------------

  N = zeros(n+1, n+1);
  for i = 0:n
    for j = 0:n-i
      N(i+1, j+1) = (-1)^(n-i-j) * nchoosek(n, j) * nchoosek(n-j, n-i-j);
    end
  end
end
