plot ellipse with given degree range

조회 수: 2 (최근 30일)
Yu Li
Yu Li 2025년 4월 14일
댓글: Mathieu NOE 2025년 7월 4일
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

답변 (3개)

Matt J
Matt J 2025년 4월 14일
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 2025년 4월 14일
이동: Image Analyst 2025년 4월 14일
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
Image Analyst
Image Analyst 2025년 4월 14일
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 2025년 7월 4일
hello @Yu Li
problem solved ?

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2025년 4월 14일
편집: Matt J 2025년 4월 14일
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

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by