plot ellipse with given degree range
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi:
I follow the way to plot ellipse in posted in this thread:
it works pretty good when I plot a full ellipse, however, when I try to plot ellipse with given range, it seems a little bit different than what I expect, example is below:
t = linspace(0,0.25*pi,100);
theta = deg2rad(0);
a=2;
b=1;
x0 = 0;
y0 = 0;
x = x0 + a*cos(t)*cos(theta) - b*sin(t)*sin(theta);
y = y0 + b*sin(t)*cos(theta) + a*cos(t)*sin(theta);
figure;
plot(x,y);
axis equal;
atand(y(end)/x(end))
the angle calculated by y(end)/x(end) is 26 degree, however, I give 0.25*pi in the theta range, it is expected to be 45 degree.
is there any mistake with my understanding?
thanks!
Yu
0 Commenti
Risposte (3)
Matt J
il 14 Apr 2025
t = linspace(0,45,100); theta=0; %degrees
a=2; b=1;
x0 = 0; y0 = 0;
N=1000;
p=translate( scale(nsidedpoly(N),[a,b]) , x0,y0);
V=interp1(linspace(-90,+270,N) ,flipud(p.Vertices),t);
plot(p,'FaceColor','none','EdgeColor','b'); hold on
plot(V(:,1), V(:,2),'r.'); hold off; axis equal
0 Commenti
Mathieu NOE
il 14 Apr 2025
Spostato: Image Analyst
il 14 Apr 2025
you would be right just in case of a circle (a = b) but in general for an ellipse with a different from b , the angle made at the end point with the origin is not the parametric angle (t) used to construct the curve
think at the ellipse as a circle being distorted (anamorphosis factor = b/a) in one direction : as the distorsion is applied only in one direction these angles cannot match
%% circle : a = b
alpha = 0.25*pi;
t = linspace(0,alpha,100);
theta = deg2rad(0);
a=1;
b=1;
x0 = 0;
y0 = 0;
x = x0 + a*cos(t)*cos(theta) - b*sin(t)*sin(theta);
y = y0 + b*sin(t)*cos(theta) + a*cos(t)*sin(theta);
figure;
plot(x,y);
hold on
plot([0 cos(alpha)],[0 sin(alpha)],'--r');
axis equal;
atand(y(end)/x(end))
%% ellipse : a =/= b
alpha = 0.25*pi;
t = linspace(0,alpha,100);
theta = deg2rad(0);
a=2;
b=1;
x0 = 0;
y0 = 0;
x = x0 + a*cos(t)*cos(theta) - b*sin(t)*sin(theta);
y = y0 + b*sin(t)*cos(theta) + a*cos(t)*sin(theta);
figure;
plot(x,y);
hold on
plot([0 cos(alpha)],[0 sin(alpha)],'--r');
axis equal;
atand(y(end)/x(end))
4 Commenti
Image Analyst
il 14 Apr 2025
Do you want the major and minor axes aligned with the axes? If not, let me know because I have code to rotate the ellipse axes by a specified angle.


Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





