Home > General-Functions > SUGR > General > Plots > sugr_plot_conic_explicit.m

sugr_plot_conic_explicit

PURPOSE ^

% explicit plot of conic (ellipse or hyperbola)

SYNOPSIS ^

function sugr_plot_conic_explicit(C,center_type,bound_type,linewidth,factor,se)

DESCRIPTION ^

% explicit plot of conic (ellipse or hyperbola)

 h = plot_conic_explicit( C, ... ) plots the conic defined by the 3x3 matrix
 C explicitly. 

 * C = conic
 * center_type = string specifying plot type of center
 * bound_type = string specifying plot type of conic
 * linewidth = width of line of conic
 * factor = magification of conic compared to position
 * se = [start,end] of hyperbola for line segments
        se=[0,0]'  then line segment (+-sqrt(2))
        se=[1,1]'  then line until xlim,ylim (default)

 $Log: plot_conic_explicit.m,v $
 Revision 1.1  2009/08/03 11:10:33  Meidow
 *** empty log message ***

 adapted
 Wolfgang Förstner 1/2011
 wfoerstn@uni-bonn.de

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% explicit plot of conic (ellipse or hyperbola)
0002 %
0003 % h = plot_conic_explicit( C, ... ) plots the conic defined by the 3x3 matrix
0004 % C explicitly.
0005 %
0006 % * C = conic
0007 % * center_type = string specifying plot type of center
0008 % * bound_type = string specifying plot type of conic
0009 % * linewidth = width of line of conic
0010 % * factor = magification of conic compared to position
0011 % * se = [start,end] of hyperbola for line segments
0012 %        se=[0,0]'  then line segment (+-sqrt(2))
0013 %        se=[1,1]'  then line until xlim,ylim (default)
0014 %
0015 % $Log: plot_conic_explicit.m,v $
0016 % Revision 1.1  2009/08/03 11:10:33  Meidow
0017 % *** empty log message ***
0018 %
0019 % adapted
0020 % Wolfgang Förstner 1/2011
0021 % wfoerstn@uni-bonn.de
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;  % number of supporting points
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;            % centre point
0048 plot( x0(1), x0(2), center_type);
0049 
0050 c00q = c00 -ch0'*inv(Chh+eps*eye(2))*ch0;                                  %#ok<MINV>
0051 [Rho,Lambda] = eig( -Chh/ (c00q+eps) );
0052 
0053 lambda = diag(Lambda);
0054 
0055 hold on
0056 switch sign(d)
0057     case +1
0058         %% Ellipse
0059         plot( x0(1), x0(2), center_type);
0060         %  (1) plot ellipse
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         %% Hyperbola
0076         % (2) plot hyperbola
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         %         t = linspace(-asinh(a), +asinh(a), N);
0085         %         % t = linspace(-pi,pi, N);
0086         %
0087         %         x = sqrt(1/-lambda(1)) *sinh(t);
0088         %         y = sqrt(1/+lambda(2))* cosh(t);
0089          
0090         
0091         if se(1) ~= 0 && se(2) ~= 0 || se(1) ~= 1 && se(2) ~= 1     % bounds given
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            % bounds by xlim and ylim
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                      % line segment
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

Generated on Mon 08-Jan-2018 17:21:49 by m2html © 2005