plot half of an ellipse with a=40 and b=20 in 3d in matlab

To plot half of an ellipse with a=40 and b=20 in 3D using Matlab, we can use the elliptic integrals and the parametric form of the ellipse.

Assuming the ellipse is in the xy plane, we can define the ellipse in parametric form as:

main.m
x = a*cos(t);
y = b*sin(t);
28 chars
3 lines

where t ranges from 0 to π (which gives half of the ellipse). To plot this in 3D, we can add a z coordinate as:

main.m
z = zeros(size(x));
20 chars
2 lines

This will place the ellipse in the xy plane. We can then plot these three vectors using plot3 function in Matlab, as follows:

main.m
a = 40;
b = 20;
t = linspace(0,pi,100);

x = a*cos(t);
y = b*sin(t);
z = zeros(size(x));

plot3(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
139 chars
13 lines

This will plot a half of the ellipse with a=40 and b=20 in 3D.

Note: To make the ellipse appear more elliptical and less circular, we can set the aspect ratio of the plot to daspect([1 1 b/a]).

main.m
a = 40;
b = 20;
t = linspace(0,pi,100);

x = a*cos(t);
y = b*sin(t);
z = zeros(size(x));

plot3(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
daspect([1 1 b/a])
158 chars
14 lines

related categories

gistlibby LogSnag