Rev | Line | |
---|
[37] | 1 | function h = draw_line_clip(m,b,a, linespec, varargin) |
---|
| 2 | %DRAW_LINE_CLIP Draw a line defined by an equation. |
---|
| 3 | % DRAW_LINE_CLIP(M,B,A) draws a line, clipped to the current axes, |
---|
| 4 | % defined by a*y = m*x + b. |
---|
| 5 | % DRAW_LINE_CLIP(M,B,A,LINESPEC) also specifies the line style and color. |
---|
| 6 | |
---|
| 7 | if nargin < 4 |
---|
| 8 | linespec = 'b'; |
---|
| 9 | end |
---|
| 10 | v = axis; |
---|
| 11 | x1 = v(1); |
---|
| 12 | x2 = v(2); |
---|
| 13 | warning off |
---|
| 14 | y1 = (m*x1 + b)/a; |
---|
| 15 | y2 = (m*x2 + b)/a; |
---|
| 16 | warning on |
---|
| 17 | if y1 < v(3) |
---|
| 18 | y1 = v(3); |
---|
| 19 | x1 = (a*y1 - b)/m; |
---|
| 20 | end |
---|
| 21 | if y1 > v(4) |
---|
| 22 | y1 = v(4); |
---|
| 23 | x1 = (a*y1 - b)/m; |
---|
| 24 | end |
---|
| 25 | if y2 < v(3); |
---|
| 26 | y2 = v(3); |
---|
| 27 | x2 = (a*y2 - b)/m; |
---|
| 28 | end |
---|
| 29 | if y2 > v(4); |
---|
| 30 | y2 = v(4); |
---|
| 31 | x2 = (a*y2 - b)/m; |
---|
| 32 | end |
---|
| 33 | h = line([x1 x2], [y1 y2]); |
---|
| 34 | set_linespec(h,linespec); |
---|
| 35 | if length(varargin) > 0 |
---|
| 36 | set(h,varargin{:}); |
---|
| 37 | end |
---|
| 38 | if nargout < 1 |
---|
| 39 | clear h |
---|
| 40 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.