Plot ellipsoid with only principal section lines

8 visualizaciones (últimos 30 días)
chicken vector
chicken vector el 26 de Mayo de 2021
Editada: Adam Danz el 26 de Mayo de 2021
I have always used the Matlab function ellipsoid as follows:
[X,Y,Z] = ellipsoid(0,0,0,1,2,3,16);
figure
surf(X,Y,Z,'facecolor','none')
axis equal; grid off;
And it gives the following image:
I'd like to plot an ellipsoid like the following one:
Is there a way on Matlab?

Respuesta aceptada

Adam Danz
Adam Danz el 26 de Mayo de 2021
Editada: Adam Danz el 26 de Mayo de 2021
This solution produces a white ellipsoid surface with transparency so that lines in the back are faded. Then it adds the major circumferential lines by computing them manually.
% Define center and radii
cnt = [0 0 0]; % center point, row vec
xyzR = [1 2 3]; % radii, row vec
% Compute major circumferential lines.
th = linspace(0,2*pi,150)'; % column vec
ex = @(r,c)c+r*cos(th); % r=radius (scalar), c=center (Scalar)
ey = @(r,c)c+r*sin(th); % r=radius (scalar), c=center (Scalar)
ez = @(c)repmat(c,size(th)); % c=center (scalar)
xy = [ex(xyzR(1),cnt(1)), ey(xyzR(2),cnt(2)), ez(cnt(3)) ];
xz = [ex(xyzR(1),cnt(1)), ez(cnt(2)), ey(xyzR(3),cnt(3))];
yz = [ez(cnt(1)), ey(xyzR(2),cnt(2)), ex(xyzR(3),cnt(3))];
% Plot white, partially transparent ellipsoid
clf
[X,Y,Z] = ellipsoid(cnt(1),cnt(2),cnt(3),xyzR(1),xyzR(2),xyzR(3),16);
sh = surf(X,Y,Z,'facecolor','w','EdgeColor','none','FaceAlpha',.33);
hold on;
xlabel('x'); ylabel('y'); zlabel('z')
% Add circumferential lines
plot3(cnt(1), cnt(2), cnt(3), 'ko','MarkerSize',8,'MarkerFaceColor','k') % center point
lw = 2; % line widths
plot3(xy(:,1), xy(:,2), xy(:,3), 'k-','LineWidth',lw)
plot3(xz(:,1), xz(:,2), xz(:,3), 'k-','LineWidth',lw)
plot3(yz(:,1), yz(:,2), yz(:,3), 'k-','LineWidth',lw)
% Add origin lines
endPoints = (cnt + xyzR).*[-1 -1 1];
plot3([cnt(1),endPoints(1)],cnt([2,2]), cnt([3,3]), 'b-','LineWidth',lw)
plot3(cnt([1,1]), [cnt(2),endPoints(2)],cnt([3,3]), 'b-','LineWidth',lw)
plot3(cnt([1,1]), cnt([2,2]),[cnt(3),endPoints(3)], 'b-','LineWidth',lw)
axis equal
view(-60, 23)
grid off
edit: no content change; cleaned up code by aligning xy, xz, yx matrices.
  2 comentarios
chicken vector
chicken vector el 26 de Mayo de 2021
This is very good. Somehow I did not think about drawing the lines manually.
Thank you very much!
Adam Danz
Adam Danz el 26 de Mayo de 2021
I'm still not convinced it's the smoothest solution but it does the job. I'd be happy to see alternatives.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by