1 %% Copyright (c) 2011, INRA
2 %% 2003-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} = } drawEllipseArc (@var{arc})
36 %% Draw an ellipse arc on the current axis.
38 %% drawEllipseArc(ARC)
39 %% draw ellipse arc specified by ARC. ARC has the format:
40 %% ARC = [XC YC A B THETA T1 T2]
42 %% ARC = [XC YC A B T1 T2] (isothetic ellipse)
43 %% with center (XC, YC), main axis of half-length A, second axis of
44 %% half-length B, and ellipse arc running from t1 to t2 (both in degrees,
45 %% in Counter-Clockwise orientation).
47 %% Parameters can also be arrays. In this case, all arrays are suposed to
48 %% have the same size...
51 %% % draw an ellipse arc: center = [10 20], radii = 50 and 30, theta = 45
52 %% arc = [10 20 50 30 45 -90 270];
54 %% axis([-50 100 -50 100]); axis equal;
56 %% drawEllipseArc(arc, 'color', 'r')
58 %% % draw another ellipse arc, between angles -60 and 70
59 %% arc = [10 20 50 30 45 -60 (60+70)];
61 %% axis([-50 100 -50 100]); axis equal;
63 %% drawEllipseArc(arc, 'LineWidth', 2);
64 %% ray1 = createRay([10 20], deg2rad(-60+45));
66 %% ray2 = createRay([10 20], deg2rad(70+45));
70 %% @seealso{ellipses2d, drawEllipse, drawCircleArc}
73 function varargout = drawEllipseArc(varargin)
75 %% Extract input arguments
77 % extract dawing style strings
79 for i = 1:length(varargin)
80 if ischar(varargin{i})
81 styles = varargin(i:end);
87 if length(varargin)==1
88 ellipse = varargin{1};
98 theta = zeros(size(x0));
103 elseif length(varargin)>=6
108 if length(varargin)>6
111 extent = varargin{7};
113 theta = zeros(size(x0));
115 extent = varargin{6};
119 error('drawellipse: please specify center x, center y and radii a and b');
125 % allocate memory for handles
129 % start and end angles
131 t2 = t1 + deg2rad(extent);
133 % vertices of ellipse
134 t = linspace(t1, t2, 60);
136 % convert angles to ellipse parametrisation
138 t(sup) = atan(a(i) / b(i) * tan(t(sup)));
139 t(~sup) = atan2(a(i) / b(i) * tan(2*pi - t(~sup)), -1);
142 % precompute cos and sin of theta (given in degrees)
143 cot = cosd(theta(i));
144 sit = sind(theta(i));
146 % compute position of points
147 xt = x0(i) + a(i)*cos(t)*cot - b(i)*sin(t)*sit;
148 yt = y0(i) + a(i)*cos(t)*sit + b(i)*sin(t)*cot;
150 h(i) = plot(xt, yt, styles{:});
154 %% Process output arguments