-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathellipsedraw.m
84 lines (67 loc) · 2.06 KB
/
ellipsedraw.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
function hEllipse = ellipsedraw(hand,a,b,x0,y0,phi,lineStyle)
%ELLIPSEDRAW can draw an arbitrary ellipse with given parameters.
% The properties of that ellipse plot can be customized
% by setting the ellipse handle.
%
% hEllipse = ellipsedraw(hand,a,b,x0,y0,phi,lineStyle)
%
% Input parameters:
% hand Parent handle for ellipse
% a Value of the major axis
% b Value of the minor axis
% x0 Abscissa of the center point of the ellipse
% y0 Ordinate of the center point of the ellipse
% phi Angle between x-axis and the major axis
% lineStyle Definition of the plotted line style
%
% Output:
% hEllipse Handle of the ellipse
%
% Simple usage:
% ellipsedraw(5,3);
% ellipsedraw(5,3,'g--');
% ellipsedraw(5,3,pi/4);
%
% Complete usage:
% h = ellipsedraw(5,3,1,-2,pi/4,'r-.');
% set(h,'LineWidth',2);
% Designed by: Lei Wang, <[email protected]>, 25-Mar-2003.
% Last Revision: 01-Apr-2003.
% Dept. Mechanical & Aerospace Engineering, NC State University.
% Copyright (c)2003, Lei Wang <[email protected]>
%$Revision: 1.0 $ $ 4/1/2003 5:42:24 PM $
if (nargin < 3)||(nargin > 7),
error('Too few or too many arguments.');
elseif nargin == 3
x0 = 0; y0 = 0;
phi = 0; lineStyle = 'b-';
elseif nargin == 4
if ischar(x0) == 1
lineStyle = x0;
x0 = 0; y0 = 0;
phi = 0;
else
phi = x0;
x0 = 0; y0 = 0;
lineStyle = 'b-';
end
elseif nargin == 5
phi = 0; lineStyle = 'b-';
elseif nargin == 6
lineStyle = 'b-';
end
theta = [-0.03:0.01:2*pi];
% Parametric equation of the ellipse
%----------------------------------------
x = a*cos(theta);
y = b*sin(theta);
% Coordinate transform
%----------------------------------------
X = cos(phi)*x - sin(phi)*y;
Y = sin(phi)*x + cos(phi)*y;
X = X + x0;
Y = Y + y0;
% Plot the ellipse
%----------------------------------------
hEllipse = plot(hand,X,Y,lineStyle);
%axis equal;