The answers from Jacob and Amro are very good examples for computing and plotting points for an ellipse. I'll address some easy ways you can plot an ellipsoid...
First, MATLAB has a built-in function ELLIPSOID which generates a set of mesh points given the ellipsoid center and the semi-axis lengths. The following creates the matrices x
, y
, and z
for an ellipsoid centered at the origin with semi-axis lengths of 4, 2, and 1 for the x, y, and z directions, respectively:
[x,y,z] = ellipsoid(0,0,0,4,2,1);
You can then use the function MESH to plot it, returning a handle to the plotted surface object:
hMesh = mesh(x,y,z);
If you want to rotate the plotted ellipsoid, you can use the ROTATE function. The following applies a rotation of 45 degrees around the y-axis:
rotate(hMesh,[0 1 0],45);
You can then adjust the plot appearance to get the following figure:
axis equal; %# Make tick mark increments on all axes equal
view([-36 18]); %# Change the camera viewpoint
xlabel('x');
ylabel('y');
zlabel('z');
Also, if you want to use the rotated plot points for further calculations, you can get them from the plotted surface object:
xNew = get(hMesh,'XData'); %# Get the rotated x points
yNew = get(hMesh,'YData'); %# Get the rotated y points
zNew = get(hMesh,'ZData'); %# Get the rotated z points