# What is the function to plot a rotating 3-D ellipsoid

조회 수: 10 (최근 30일)
James Timana 2011년 10월 28일
I want to make a rotating ellips using mathematical equations on matlab, i must also be able to control rotating speed and direrection

댓글을 달려면 로그인하십시오.

### 채택된 답변

Amith Kamath 2011년 10월 29일
편집: Randy Souza 2013년 9월 11일
function [] = visualizeDTrot(C,M,speed,Dir,time)
%%C: the covariance matrix.
%%Dir: direction of the estimate, to be plotted together with the DT ellipsoid.
%%M: the mean vector, usually 0 in case of DT.
%%speed: time to pause between plotting, lowervalue = faster.
%%Dir: 1 or -1 for clockwise, anticlockwise.
%%time: number of iterations for which rotation is needed, higher = longer.
%%example: visualizeDTrot(diag([17 2 2]),[0 0 0],0.4,1,100)
[U,L] = eig(C);
% For N standard deviations spread of data, the radii of the eliipsoid will
% be given by N*SQRT(eigenvalues).
N = 1; % choose your own N
% generate data for "unrotated" ellipsoid
% rotate data with orientation matrix U and center M
a = kron(U(:,1),xc); b = kron(U(:,2),yc); c = kron(U(:,3),zc);
data = a+b+c; n = size(data,2);
x = data(1:n,:)+M(1); y = data(n+1:2*n,:)+M(2); z = data(2*n+1:end,:)+M(3);
% now plot the rotated ellipse
if Dir == 1
i = 1:time;
else
i = time:-1:1;
end
for j = i
sc = mesh(x,y,z);
colormap copper
zdir = [1 0 0];
axis equal
rotate(sc,zdir,j)
pause(speed)
title('actual ellipsoid represented by data: C and M')
axis equal
xlabel('x axis ---->')
ylabel('y axis ---->')
zlabel('z axis ---->')
alpha(0.5)
end
%%This should do the job!

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by