Problem in plot combination

조회 수: 1 (최근 30일)
Dimitris Arapidis
Dimitris Arapidis 2013년 9월 13일
I have the following code:
dmin=0;
dmax=17.502503873106170;
zmin=8.735508217599295e+02;
zmax=2.249914400000071e+02;
axis (axis)
plot([dmin dmax],[zmin zmax],'r')
x1=dmin;
y1=zmin;
x2=dmax;
y2=zmax;
f = 100000;
r = 8.657*sqrt(dmax/f);
e = sqrt(1-(r/dmax)^2);
a = 1/2*sqrt((x2-x1)^2+(y2-y1)^2);
b = a*sqrt(1-e^2);
t = linspace(0,2*pi);
X = a*cos(t);
Y = b*sin(t);
w = atan2(y2-y1,x2-x1);
x = (x1+x2)/2 + X*cos(w) - Y*sin(w);
y = (y1+y2)/2 + X*sin(w) + Y*cos(w);
hold on, plot(x,y,'g-')
dmin, zmin are the x,y coordinates for point A, dmax, zmax are the x,y coordinates for point B. AB is both a straight line and the major axis of an ellipse. e is the eccentrity of the ellipse.
When i plot both line and ellipse the ellipse end up wrong. What should i do in order to plot the line as the ellipse major axis?

답변 (1개)

Roger Stafford
Roger Stafford 2013년 9월 13일
편집: Roger Stafford 2013년 9월 13일
Do you have the plot scaling the same for both the x and y axes? If not, that would distort the ellipse. Use
axis equal
  댓글 수: 2
Dimitris Arapidis
Dimitris Arapidis 2013년 9월 13일
I already tried that, it didn't work
Roger Stafford
Roger Stafford 2013년 9월 13일
I ran your program. Without the "axis equal" line the ellipse is naturally distorted because the scaling in x and y is so different in the plot and the two vertices at the ends of the major axis don't look like vertices.
With "axis equal" present the ellipse shows its true nature. Its eccentricity is so close to one (.99997859) that it is nearly a vertical straight line segment and the red line marking its major axis segment is nearly obscured. With equal scaling matlab is giving an accurate picture of the ellipse as it really is. Both the ellipse and the major axis are very nearly coincident vertical line segments.

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

카테고리

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