% hline draws a line if it's given in homogeneous coords, or two hom. % points are given. The third argument can specify a color. function hline(a,b,c) col = 'blue'; % default colour flag = 0; if nargin >= 2 & isa(a,'double') & isa(b,'double') % Two points specified a = hcross(a,b); flag = 1; if nargin == 3 & isa(c,'char') % 2 points and a colour specified col = c; end end if (nargin >= 1 & isa(a,'double')) | (flag == 1) % A single line specified if abs(a(1)) > abs(a(2)) % line is more vertical ylim = get(get(gcf,'CurrentAxes'),'Ylim'); p1 = hcross(a, [0 1 0]'); p2 = hcross(a, [0 -1/ylim(2) 1]'); else % line more horizontal xlim = get(get(gcf,'CurrentAxes'),'Xlim'); p1 = hcross(a, [1 0 0]'); p2 = hcross(a, [-1/xlim(2) 0 1]'); end if nargin == 2 & isa(b,'char') % 1 line vector and a colour specified col = b; end else error('Bad arguments passed to hline'); end line([p1(1) p2(1)], [p1(2) p2(2)], 'color', col);