Problem in plot combination

2 次查看(过去 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