Plot ellipsoid with only principal section lines
조회 수: 11 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Adam Danz
2021년 5월 26일
편집: Adam Danz
2021년 5월 26일
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
Adam Danz
2021년 5월 26일
I'm still not convinced it's the smoothest solution but it does the job. I'd be happy to see alternatives.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
