function simplified_f = piao_simplify_conic(a)
% Description: simplify the conic funtion to normalized form (简化二次曲线使得成为标准型)
%
% Input: a 1*6 or 6*1 matrix :(a11, 2*a12, a22, 2*a13, 2*a23, a33)
% the coefficients of conic funtion :a11*x.^2 + 2*a12*x*y + a22*y.^2 + 2*a13*x + 2*a23*y +a33
%
% Output: normalized conic funtion in symbolic form
%
%
% Method: 采用不变量化简二次曲线 参考《解析几何》(吕林根, 许子道等编 ,高等教育出版社)
%
%
%
% Author: piao
% Email: zjut.2046@yahoo.com.cn
% Date: 2008-12-10
% Matlab version: 7.6.0.324 (R2008a)
%% according to the number of input variables do sth
if length(a) ~=6
error('input data must be 1*6 or 6*1 matrix ')
end
%%
% ---------------------main process------------------
a11=a(1);
a12=a(2)/2;
a22=a(3);
a13=a(4)/2;
a23=a(5)/2;
a33=a(6);
I1 = a11 + a22; % invariable variable I1 (whose value will not change after coordinate axes rotation or translation )
I2_m = [a11 a12; a12 a22];
I2 = det(I2_m); % invariable variable I2
I3_m = [a11 a12 a13; a12 a22 a23; a13 a23 a33];
I3 = det( I3_m ) ;
K1_m1 = [a11 a13; a13 a33];
K1_m2 = [a22 a23; a23 a33];
K1 = det(K1_m1) + det(K1_m2);
syms x y
%-------------------- case 1: I2~=0 ---> central curve (ellipse or hyperbola 椭圆或者双曲线)---------------------
if I2~=0
xx=solve('x*x - I1*x + I2=0','x' );
lambda=eval(xx);
% may be have problems here? the positions of lambda(1) and lambda(2) can exchange
simplified_f = lambda(1)*x*x + lambda(2)*y*y + I2/I2;
%? simplified_f = lambda(2)*x*x + lambda(1)*y*y + I2/I2;
end
%-------------------- case 2: I2==0 & I3~=0 ---> non-central curve (parabola 抛物线)---------------------
if I2 == 0 & I3~=0
simplified_f = I1*y*y +2*sqrt(-I3/I1)*x;
% also can be simplified_f = I1*y*y - 2*sqrt(-I3/I1)*x
end
%-------------------- case 3: I2==0 & I3==0 ---> linear curve(just two parallel lines )---------------------
if I2 == 0 & I3==0
simplified_f = I1*y*y + K1/I1;
end