plot ellipse with given degree range

3 Ansichten (letzte 30 Tage)
Yu Li
Yu Li am 14 Apr. 2025
Kommentiert: Mathieu NOE am 4 Jul. 2025
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

Antworten (3)

Matt J
Matt J am 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

Mathieu NOE
Mathieu NOE am 14 Apr. 2025
Verschoben: Image Analyst am 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))
ans = 45
%% 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))
ans = 26.5651
  4 Kommentare
Image Analyst
Image Analyst am 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.
Mathieu NOE
Mathieu NOE am 4 Jul. 2025
hello @Yu Li
problem solved ?

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 14 Apr. 2025
Bearbeitet: Matt J am 14 Apr. 2025
Using this FEX package,
t = linspace(0,45,100); theta=0; %degrees
a=2; b=1;
x0 = 0; y0 = 0;
xy=ellipticalFit.xysim([x0,y0],[a,b],theta, t);
plot(xy(1,:), xy(2,:),'.'); axis padded

Kategorien

Mehr zu Graphics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by