forked from petercorke/toolbox-common-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_homline.m
74 lines (62 loc) · 2.1 KB
/
plot_homline.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%PLOT_HOMLINE Draw a line in homogeneous form
%
% PLOT_HOMLINE(L, LS) draws a line in the current plot defined by L.X = 0 where L
% (3x1). The current axis limits are used to determine the endpoints of
% the line. MATLAB line specification LS can be set. If L (3xN) then N
% lines are drawn, one per column.
%
% H = PLOT_HOMLINE(L, LS) as above but returns a vector of graphics handles for the lines.
%
% Notes::
% - The line(s) is added to the current plot.
% - The line(s) can be drawn in 3D axes but will always lie in the
% xy-plane.
%
% See also PLOT_BOX, PLOT_POLY, HOMLINE.
% TODO, probably should be part of a HomLine class.
% Copyright (C) 1993-2017, by Peter I. Corke
%
% This file is part of The Robotics Toolbox for MATLAB (RTB).
%
% RTB is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RTB is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with RTB. If not, see <http://www.gnu.org/licenses/>.
%
% http://www.petercorke.com
function handles = plot_homline(lines, varargin)
% get plot limits from current graph
xlim = get(gca, 'XLim');
ylim = get(gca, 'YLim');
ish = ishold;
hold on;
if min(size(lines)) == 1
lines = lines(:);
end
assert(numrows(lines) == 3, 'RTB:plot_homline:badarg', 'Input must be a 3-vector or 3xN matrix');
h = [];
% for all input lines (columns
for l=lines
if abs(l(2)) > abs(l(1))
y = (-l(3) - l(1)*xlim) / l(2);
hh = plot(xlim, y, varargin{:});
else
x = (-l(3) - l(2)*ylim) / l(1);
hh = plot(x, ylim, varargin{:});
end
h = [h; hh];
end
if ~ish
hold off
end
if nargout > 0,
handles = h;
end