0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 function sugr_plot_conic_explicit...
0024 (C,center_type,bound_type,linewidth,factor,se)
0025
0026
0027 if nargin < 4
0028 linewidth=2;
0029 end
0030 if nargin < 5
0031 factor=1;
0032 end
0033 if nargin < 6
0034 se = [1,1];
0035 end
0036
0037 C = C/norm(C+eps);
0038 N0=50;
0039 N = 2*N0;
0040
0041
0042 Chh = C(1:2,1:2);
0043 ch0 = C(1:2, 3);
0044 c00 = C( 3, 3);
0045
0046 d = det( Chh +eps*eye(2));
0047 x0 = -inv(Chh+eps*eye(2)) *ch0;
0048 plot( x0(1), x0(2), center_type);
0049
0050 c00q = c00 -ch0'*inv(Chh+eps*eye(2))*ch0;
0051 [Rho,Lambda] = eig( -Chh/ (c00q+eps) );
0052
0053 lambda = diag(Lambda);
0054
0055 hold on
0056 switch sign(d)
0057 case +1
0058
0059 plot( x0(1), x0(2), center_type);
0060
0061 if lambda(1)<0
0062 lambda = -lambda;
0063 end
0064
0065 lambda=lambda/factor^2;
0066
0067 t = linspace(0,2*pi, N);
0068
0069 x = sqrt(1/lambda(1)) * sin(t);
0070 y = sqrt(1/lambda(2)) * cos(t);
0071 x = bsxfun(@plus, Rho * [x; y], x0);
0072 plot( x(1,:), x(2,:), bound_type,'LineWidth',linewidth);
0073
0074 case -1
0075
0076
0077 if lambda(2)<0
0078 lambda = flipud(lambda);
0079 Rho = fliplr(Rho);
0080 end
0081
0082 lambda(2)=lambda(2)/factor^2;
0083
0084
0085
0086
0087
0088
0089
0090
0091 if se(1) ~= 0 && se(2) ~= 0 || se(1) ~= 1 && se(2) ~= 1
0092 t = linspace(atan(se(1)*sqrt(-lambda(1))),atan(se(2)*sqrt(-lambda(1))),N);
0093 end
0094 if se(1) == 1 && se(2) == 1
0095 dir = Rho(:,1);
0096 xl = xlim;
0097 yl = ylim;
0098 s1 = dir'*[xl(1)-x0(1);yl(1)-x0(2)];
0099 s2 = dir'*[xl(1)-x0(1);yl(2)-x0(2)];
0100 s3 = dir'*[xl(2)-x0(1);yl(2)-x0(2)];
0101 s4 = dir'*[xl(2)-x0(1);yl(1)-x0(2)];
0102 se(1) = min([s1,s2,s3,s4])-1;
0103 se(2) = max([s1,s2,s3,s4])+1;
0104 t = linspace(atan(se(1)*sqrt(-lambda(1))),atan(se(2)*sqrt(-lambda(1))),N);
0105 end
0106 if se(1) == 0 && se(2) == 0
0107 t = linspace(-pi/4,pi/4,N);
0108 end
0109 x = sqrt(1/-lambda(1)) * tan(t);
0110 y = sqrt(1/+lambda(2)) ./ cos(t);
0111
0112 x1 = repmat(x0, 1, N) + Rho*[x; +y];
0113 x2 = repmat(x0, 1, N) + Rho*[x; -y];
0114 plot( x1(1,:), x1(2,:), bound_type,'LineWidth',linewidth);
0115 plot( x2(1,:), x2(2,:), bound_type,'LineWidth',linewidth);
0116 plot( [(x1(1,1)+x2(1,1))/2,(x1(1,N)+x2(1,N))/2],...
0117 [(x1(2,1)+x2(2,1))/2,(x1(2,N)+x2(2,N))/2] ,center_type);
0118
0119
0120 otherwise
0121 error('degenrated conic')
0122 end