]> Creatis software - CreaPhase.git/blob - octave_packages/geometry-1.5.0/geom2d/drawCircleArc.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / geometry-1.5.0 / geom2d / drawCircleArc.m
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>
4 %%
5 %% All rights reserved.
6 %% (simplified BSD License)
7 %%
8 %% Redistribution and use in source and binary forms, with or without
9 %% modification, are permitted provided that the following conditions are met:
10 %%
11 %% 1. Redistributions of source code must retain the above copyright notice, this
12 %%    list of conditions and the following disclaimer.
13 %%     
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.
17 %%
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.
29 %%
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.
33
34 %% -*- texinfo -*-
35 %% @deftypefn {Function File} {@var{h} = } drawCircleArc (@var{xc}, @var{yc}, @var{r}, @var{start}, @var{end})
36 %% @deftypefnx {Function File} {@var{h} = } drawCircleArc (@var{arc})
37 %% @deftypefnx {Function File} {@var{h} = } drawCircleArc (@dots{}, @var{param}, @var{value})
38 %% Draw a circle arc on the current axis
39 %%
40 %%   drawCircleArc(XC, YC, R, START, EXTENT);
41 %%   Draws circle with center (XC, YC), with radius R, starting from angle
42 %%   START, and with angular extent given by EXTENT. START and EXTENT angles
43 %%   are given in degrees.
44 %%
45 %%   drawCircleArc(ARC);
46 %%   Puts all parameters into one single array.
47 %%
48 %%   drawCircleArc(..., PARAM, VALUE);
49 %%   specifies plot properties by using one or several parameter name-value
50 %%   pairs.
51 %%
52 %%   H = drawCircleArc(...);
53 %%   Returns a handle to the created line object.
54 %%
55 %%   @example
56 %%     % Draw a red thick circle arc
57 %%     arc = [10 20 30 -120 240];
58 %%     figure;
59 %%     axis([-50 100 -50 100]);
60 %%     hold on
61 %%     drawCircleArc(arc, 'LineWidth', 3, 'Color', 'r')
62 %% @end example
63 %%
64 %%   @seealso{circles2d, drawCircle, drawEllipse}
65 %% @end deftypefn
66
67 function varargout = drawCircleArc(varargin)
68
69   if nargin == 0
70       error('Need to specify circle arc');
71   end
72
73   circle = varargin{1};
74   if size(circle, 2) == 5
75       x0  = circle(:,1);
76       y0  = circle(:,2);
77       r   = circle(:,3);
78       start   = circle(:,4);
79       extent  = circle(:,5);
80       varargin(1) = [];
81       
82   elseif length(varargin) >= 5
83       x0  = varargin{1};
84       y0  = varargin{2};
85       r   = varargin{3};
86       start   = varargin{4};
87       extent  = varargin{5};
88       varargin(1:5) = [];
89       
90   else
91       error('drawCircleArc: please specify center, radius and angles of circle arc');
92   end
93
94   % convert angles in radians
95   t0  = deg2rad(start);
96   t1  = t0 + deg2rad(extent);
97
98   % number of line segments
99   N = 60;
100
101   % initialize handles vector
102   h   = zeros(length(x0), 1);
103
104   % draw each circle arc individually
105   for i = 1:length(x0)
106       % compute basis
107       t = linspace(t0(i), t1(i), N+1)';
108
109       % compute vertices coordinates
110       xt = x0(i) + r(i)*cos(t);
111       yt = y0(i) + r(i)*sin(t);
112       
113       % draw the circle arc
114       h(i) = plot(xt, yt, varargin{:});
115   end
116
117   if nargout > 0
118       varargout = {h};
119   end
120
121
122 endfunction
123