1 %% Copyright (c) 2011, INRA
2 %% 2005-2011, David Legland <david.legland@grignon.inra.fr>
3 %% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
5 %% All rights reserved.
6 %% (simplified BSD License)
8 %% Redistribution and use in source and binary forms, with or without
9 %% modification, are permitted provided that the following conditions are met:
11 %% 1. Redistributions of source code must retain the above copyright notice, this
12 %% list of conditions and the following disclaimer.
14 %% 2. Redistributions in binary form must reproduce the above copyright notice,
15 %% this list of conditions and the following disclaimer in the documentation
16 %% and/or other materials provided with the distribution.
18 %% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 %% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 %% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 %% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 %% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 %% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 %% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 %% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 %% POSSIBILITY OF SUCH DAMAGE.
30 %% The views and conclusions contained in the software and documentation are
31 %% those of the authors and should not be interpreted as representing official
32 %% policies, either expressed or implied, of copyright holder.
35 %% @deftypefn {Function File} {@var{h} =} drawCenteredEdge (@var{center}, @var{L}, @var{theta})
36 %% @deftypefnx {Function File} {@var{h} =} drawCenteredEdge (@var{edge})
37 %% @deftypefnx {Function File} {@var{h} =} drawCenteredEdge (@dots{}, @var{name},@var{value})
38 %% Draw an edge centered on a point.
40 %% drawCenteredEdge(CENTER, L, THETA)
41 %% Draws an edge centered on point CENTER, with length L, and orientation
42 %% THETA (given in degrees). Input arguments can also be arrays, that must
43 %% all have the same number odf rows.
45 %% drawCenteredEdge(EDGE)
46 %% Concatenates edge parameters into a single N-by-4 array, containing:
49 %% drawCenteredEdge(..., NAME, VALUE)
50 %% Also specifies drawing options by using one or several parameter name -
51 %% value pairs (see doc of plot function for details).
53 %% H = drawCenteredEdge(...)
54 %% Returns handle(s) to the created edges(s).
57 %% % Draw an ellipse with its two axes
62 %% elli = [center r1 r2 theta];
63 %% drawEllipse(elli, 'linewidth', 2);
64 %% axis([0 100 0 100]); axis equal;
66 %% edges = [center 2*r1 theta ; center 2*r2 theta+90];
67 %% drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g');
70 %% @seealso{edges2d, drawEdge}
73 function varargout = drawCenteredEdge(center, len, theta, varargin)
75 %% process input variables
77 if size(center, 2) == 4
78 % manage edge in single parameter
80 varargin = [{len, theta}, varargin];
84 center = center(:, 1:2);
89 % parameters given in different arguments
97 % ensure all data have same size
99 if NP == 1, center = repmat(center, [N 1]); end
100 if NL == 1, len = repmat(len, [N 1]); end
101 if ND == 1, theta = repmat(theta, [N 1]); end
106 % extract drawing options
107 options = varargin(:);
112 % coordinates of center point
116 % convert angle to radians
117 theta = theta * pi / 180;
119 % computation shortcuts
123 % compute starting and ending points
124 x1 = xc - len .* cot / 2;
125 x2 = xc + len .* cot / 2;
126 y1 = yc - len .* sit / 2;
127 y2 = yc + len .* sit / 2;
133 h(i) = plot([x1(i) x2(i)], [y1(i) y2(i)]);
136 % apply style to edges
137 if ~isempty(options) > 0
139 set(h(i), options{:});
146 % process output arguments