1 | % HLINE - Plot 2D lines defined in homogeneous coordinates. |
---|
2 | % |
---|
3 | % Function for ploting 2D homogeneous lines defined by 2 points |
---|
4 | % or a line defined by a single homogeneous vector |
---|
5 | % |
---|
6 | % Usage: hline(p1,p2) where p1 and p2 are 2D homogeneous points. |
---|
7 | % hline(p1,p2,'colour_name') 'black' 'red' 'white' etc |
---|
8 | % hline(l) where l is a line in homogeneous coordinates |
---|
9 | % hline(l,'colour_name') |
---|
10 | % |
---|
11 | |
---|
12 | % Peter Kovesi |
---|
13 | % School of Computer Science & Software Engineering |
---|
14 | % The University of Western Australia |
---|
15 | % pk @ csse uwa edu au |
---|
16 | % http://www.csse.uwa.edu.au/~pk |
---|
17 | % |
---|
18 | % April 2000 |
---|
19 | |
---|
20 | function hline(a,b,c) |
---|
21 | |
---|
22 | col = 'blue'; % default colour |
---|
23 | |
---|
24 | if nargin >= 2 & isa(a,'double') & isa(b,'double') % Two points specified |
---|
25 | |
---|
26 | p1 = a./a(3); % make sure homogeneous points lie in z=1 plane |
---|
27 | p2 = b./b(3); |
---|
28 | |
---|
29 | if nargin == 3 & isa(c,'char') % 2 points and a colour specified |
---|
30 | col = c; |
---|
31 | end |
---|
32 | |
---|
33 | elseif nargin >= 1 & isa(a,'double') % A single line specified |
---|
34 | |
---|
35 | a = a./a(3); % ensure line in z = 1 plane (not needed??) |
---|
36 | |
---|
37 | if abs(a(1)) > abs(a(2)) % line is more vertical |
---|
38 | ylim = get(get(gcf,'CurrentAxes'),'Ylim'); |
---|
39 | p1 = hcross(a, [0 1 0]'); |
---|
40 | p2 = hcross(a, [0 -1/ylim(2) 1]'); |
---|
41 | else % line more horizontal |
---|
42 | xlim = get(get(gcf,'CurrentAxes'),'Xlim'); |
---|
43 | p1 = hcross(a, [1 0 0]'); |
---|
44 | p2 = hcross(a, [-1/xlim(2) 0 1]'); |
---|
45 | end |
---|
46 | |
---|
47 | if nargin == 2 & isa(b,'char') % 1 line vector and a colour specified |
---|
48 | col = b; |
---|
49 | end |
---|
50 | |
---|
51 | else |
---|
52 | error('Bad arguments passed to hline'); |
---|
53 | end |
---|
54 | |
---|
55 | line([p1(1) p2(1)], [p1(2) p2(2)], 'color', col); |
---|