I am trying to generate points within ellipsoid and then trying to fit with smooth ellipsoid surfaces. The goal is to fit with unknown data where i have to find value of a,b and c in 3 principal axes. Rinv should be equivalent to pc. But what i am getting pc in different order. So i have to find correct order to rotate my data to matlab coordinate.
a=3;
b=5;
c=1;
index=1;
for i=1:500000
x=10*rand-5;
y=10*rand-5;
z=10*rand-5;
if ((x^2/a^2) + (y^2/b^2) + (z^2/c^2) -1) <0
C(index,:)=[x,y,z];
index=index+1;
end
end
theta=pi/4; phi=pi/6; omega = pi/3;
Rx= [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)];
Ry= [cos(phi) 0 sin(phi); 0 1 0; -sin(phi) 0 cos(phi)];
Rz= [cos(omega) -sin(omega) 0; sin(omega) cos(omega) 0; 0 0 1];
R= Rz*Ry*Rx;
Rinv = inv(R);
X = C*R;
[pc,val]=eig(X'*X); E=diag(val);
[sa,sb]= sort(pc*E, 'descend'); sb
order = [2,3,1];
nC= X*pc(:,order);
plot3(nC(:,1),nC(:,2),nC(:,3),'.')
hold on
[x, y, z] = ellipsoid(0,0,0,a,b,c,30);
hSurface=surf(x, y, z, 'FaceColor','blue','EdgeColor','none');
alpha(0.5)
Specially in this line nC= X*pc(:,order); I am finding order manually. Can any one tells (1) how to find pc order correctly. (2) Value of a,b,c for unknown data set here "[x, y, z] = ellipsoid(0,0,0,a,b,c,30)" Thanks