-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircle.m
90 lines (77 loc) · 2.28 KB
/
circle.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function h = circle(varargin)
%
% H = CIRCLE(x0, y0, R, C) creates a circular patch at position (x0,y0),
% with radius R, and color C. Returns handle to circle.
%
%
% H = CIRCLE(x0, y0, R, C, prop1, val1, ...)
%
% PROPERTIES
%
% 'Points' is used to specify the number of points specifying a polygon
% which approximates a circle. Specify this as an integer. The
% default value is 15.
%
% 'EdgeColor' is used to specify the color of the line defining the
% circle. Specify this as a RGB triple [R G B], with each
% element in the color value on the interval [0, 1].
%
% 'FillColor' is used to specify the color of the interior of the
% circle. Specify this as a RGB triple [R G B], with each
% element in the color value on the interval [0, 1].
%
% 'LineWidth' is used to specify the width of the line defining the
% circle. Specify this as a one-by-one number.
%
% 'LineStyle' is used to specify the style of the line defining the
% circle. Specify this as a character string. Some options:
%
% '-' Solid line
%
% '--' Dashed line
%
% ':' Dotted line
%
nth=30;
x0 = varargin{1};
y0 = varargin{2};
R = varargin{3};
C = varargin{4};
EdgeColor = [0 0 0];
LineWidth = 2;
LineStyle = '-';
TargetAxes = gca;
args = varargin(5:end);
while length(args) >= 2
prop = args{1};
val = args{2};
args = args(3:end);
switch prop
case 'Points'
if ischar(val)
nth = str2num(val);
else
nth = val;
end
case 'FillColor'
FillColor = val;
case 'EdgeColor'
EdgeColor = val;
case 'LineWidth'
LineWidth = val;
case 'LineStyle'
LineStyle = val;
case 'TargetAxes'
TargetAxes = val;
otherwise
error(['CIRCLE.M: ', prop, ' is an invalid property specifier.']);
end
end
thetas=[0:nth]*2*pi/nth;
dx=R*cos(thetas);
dy=R*sin(thetas);
x=x0+dx;
y=y0+dy;
h=patch(TargetAxes,x,y,C, 'EdgeColor', EdgeColor, 'LineWidth', LineWidth, ...
'LineStyle', LineStyle);
%end function circle