function A = rational_bezier2mat(c,w)
% RATIONAL_BEZIER2MAT: matrix representation of a conic section
% A = rational_bezier2mat(c,w)
% implicit form in homogeneous coordinates r'Ar = 0
% of a rational quadratic Bezier curve r
% with control points c(1:3,:) and weights w(1:3)

% degenerate case
if rank(diff(c)) < 2
   display('line segment or point')
   A = []; return
end

% values of r in homogeneous coordinates
t = [0:4]'/4;
r = [rational_bezier_curve(c,w,t) ones(5,1)];

% linear system for [a_11, a_21, a_22, a_31, a_32, a_33]
A = [r(:,1).^2, 2*r(:,1).*r(:,2), r(:,2).^2, ... 
   2*r(:,3).*r(:,1), 2*r(:,3).*r(:,2), r(:,3).^2];
A = null(A);
A = [A(1) A(2) A(4); A(2) A(3) A(5); A(4) A(5) A(6)];

