Converting 3D to 2D cloud of points

6 visualizzazioni (ultimi 30 giorni)
Alfonso
Alfonso il 30 Giu 2018
Commentato: Matt J il 4 Lug 2018
I am trying to convert a set of data which is a cloud of points from 3D to 2D, I am using this code:
% Function from 3D to 2D
function [D,R,T]=dimred(X)
T = repmat(mean(X),[size(X,1),1]);
XX = X-T;
[R,N]=eig(XX'*XX);
D=XX*R;
D=D(:,2:end);
Q=[zeros(size(D,2),1) eye(size(D,2))];
R=Q*R';
return
% 3D to 2D
[nodes_2D,R,T]=dimred(newnodes1) % R = rot matrix, T = Translation matrix
The data correctly converts to 2D, in this case, looking at the image the 3D points are rotated to the left, but for a different cloud of points it rotates it to the right. My question is the next, is there any way of forcing to apply the rotation always in the same direction? (without manually reversing the 2D red plot).
I have attached the figure and the .mat containing the cloud of points in 3D.
Thank you for any help.
  10 Commenti
Walter Roberson
Walter Roberson il 30 Giu 2018
for K = 1 : size(R,2)
s = sign(R(2,K));
R(:,K) = R(:,K) .* s;
end
You need to transform the entire eigenvector.
Alfonso
Alfonso il 1 Lug 2018
Hello Walter, it does not seem to work. For a 3D dataset 1 it flattens it to the left side, whereas for a 3D dataset 2 of the same plane as dataset 1 it flattens it to the right (same behaviour I had).
3D dataset1:
3D dataset2:

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 30 Giu 2018
Modificato: Matt J il 30 Giu 2018
This uses AxelRot (Download),
normal=null(XX);
normal=normal(:,end)*sign(normal(1,end));
rotaxis=-cross([0,0,1].',normal);
theta=asind(norm(rotaxis));
[D,R,~] = AxelRot(XX.', theta, rotaxis, []);
  11 Commenti
Alfonso
Alfonso il 4 Lug 2018
Hello Matt, with a few modifications I think I finally got it to work right. Thank you for your help.
Matt J
Matt J il 4 Lug 2018
No problem. Glad you got what you needed.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by