-
Notifications
You must be signed in to change notification settings - Fork 0
/
Secdraw.m
75 lines (68 loc) · 2.87 KB
/
Secdraw.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
75
function [xx, yy] = Secdraw(start_angle, sector_angle, radius, xcoord, ycoord)
% usage: [xx, yy] = secdraw(start_angle, sector_angle, radius, clk_wise)
%
% Input:
% start_angle - starting angle in degrees, [0 is default]
% NOTE: this can be positive or negative
% sector_angle - central angle of sector in degrees
% NOTE: if negative, plotting will be clockwise
% direction.
% radius - radius of sector (default 1)
%
% Output:
% returns the corner points (xx, yy) of a patch for a sector,
% which can plotted using the patch(...) function
% NOTE:
% 1. if less than 2 or NO output variables are given,
% secdraw(...) draws the sector on the current (or a new)
% figure
% 2. if one argument is given,
% the argument is taken as the central angle
%
% Example 1 > [xx, yy] = secdraw(45, 90, 10);
% patch( xx, yy, 'b', 'EdgeColor', 'b', 'EraseMode', 'none') ;
% set( gca, 'DataAspectRatio', [1 1 1] );
% - this will draw a sector from 45 to 90 degrees with radius=1
%
% Example 2 > secdraw( 60 )
% - this will draw a sector from 0 to 60 degrees counter
% clockwise
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% author: Laine Berhane Kahsay
%
% date : 19-Feb-2004
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 1 isempty( nargin )
%disp '';
disp '-- error in usage --------------------------------';
disp ' Not enough input arguments.';
help secdraw;
return;
elseif nargin == 1
sector_angle = start_angle;
start_angle = 0;
radius = 1;
elseif nargin == 2
radius = 1;
end
theta0 = pi*0/180; % offset angle in radians
theta1 = pi*start_angle/180; % starting angle in radians
theta = pi*sector_angle/180; % central angle in radians
angle_ratio = theta/(2*pi); % ratio of the sector to the complete circle
rho = abs(radius); % abs(...) can be removed
MaxPts = 100; % maximum number of points in a whole circle.
% if set to small # (e.g 10) the resolution
% of the curve will be poor.
% generally values greater than 50
% will give (very) good resolution
n = abs( ceil( MaxPts*angle_ratio ) );
r = [ 0; rho*ones(n+1,1); 0 ];
theta = theta0 + theta1 + [ 0; angle_ratio*(0:n)'/n; 0 ]*2*pi;
% output
[xx,yy] = pol2cart(theta,r);
% plot if not enough output variable are given
if nargout < 2
hh=patch(xx+xcoord, yy+ycoord, 'k','EdgeColor','k','EraseMode','none');
end