% plots a 2D line from homogeneous vector h [3x1] Usage: plot_2D_line(h) plots line h into current figure, using the max extend of current axis object plot_2D_line(h,x1,x2) plots line h between points x1 and x2, which are either eucledian [2x1] or homogeneous [3x1] h = plot_2D_line(h,varargin) returns line handle 06/17 Susanne Wenzel wenzel@igg.uni-bonn.de
0001 %% plots a 2D line from homogeneous vector h [3x1] 0002 % 0003 % Usage: 0004 % plot_2D_line(h) 0005 % plots line h into current figure, using the max extend of 0006 % current axis object 0007 % plot_2D_line(h,x1,x2) 0008 % plots line h between points x1 and x2, which are 0009 % either eucledian [2x1] or homogeneous [3x1] 0010 % h = plot_2D_line(h,varargin) 0011 % returns line handle 0012 % 0013 % 06/17 Susanne Wenzel 0014 % wenzel@igg.uni-bonn.de 0015 0016 function varargout = plot_2D_line(h,varargin) 0017 0018 N = @(x)x./x(3); 0019 0020 h = h./norm(h(1:2)); 0021 0022 % get the current axis objects extend 0023 x_lim = get(gca,'xlim'); 0024 y_lim = get(gca,'ylim'); 0025 0026 if nargin<3 0027 0028 % generate standardline, footpoint or origin [+d, -d] 0029 d = norm([max(abs(x_lim)); max(abs(y_lim))]); 0030 0031 S3 = [0 -1 0; 1 0 0; 0 0 0]; 0032 % footpoint 0033 zl0 = N(calc_S(h)*S3*h); 0034 % direction 0035 phi = atan2(h(2),h(1)); 0036 % start- and endpoint 0037 xs = zl0 + d*[cos(phi+pi/2);sin(phi+pi/2);0]; 0038 xe = zl0 + d*[cos(phi-pi/2);sin(phi-pi/2);0]; 0039 0040 else 0041 % given startpoint 0042 xs = varargin{1}; 0043 if numel(xs)<3, xs = N([xs;1]);end 0044 % footpoint onto the line, as startpoint for ploting 0045 xs = calc_S(h)* calc_S(xs)*diag([1,1,0])*h; 0046 0047 % given endpoint 0048 xe = varargin{2}; 0049 if numel(xe)<3, xe = N([xe;1]);end 0050 % footpoint onto the line, as endpoint for ploting 0051 xe = calc_S(h)* calc_S(xe)*diag([1,1,0])*h; 0052 0053 end 0054 0055 handle = plot([xs(1),xe(1)],[xs(2),xe(2)]); 0056 set(gca,'xlim',x_lim); 0057 set(gca,'ylim',y_lim); 0058 0059 if nargout>0 0060 varargout{1} = handle; 0061 end 0062