Converting 3D to 2D cloud of points
Show older comments
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 Comments
Walter Roberson
on 30 Jun 2018
I notice you use the eigenvectors as returned. Any scalar multiple of an eigenvector acts the same way, including negative multiples. As I do not see any code in there to explicitly normalize, I wonder if the difficulty you are facing is that some of your eigenvectors just happen to be coming out with the negative of the sign you are expecting for the purposes of rotation ?
Walter Roberson
on 30 Jun 2018
Edited: Walter Roberson
on 30 Jun 2018
Can you divide each eigenvector by its first non-zero element, so that the leading entries are all 0 or positive ?
Alfonso
on 30 Jun 2018
Walter Roberson
on 30 Jun 2018
I meant like
for K = 1 : size(R,2)
firstR = find(R(:,K),1,'first');
R(:,K) = R(:,K) ./ firstR;
end
... Of course there are ways to vectorize this, but it is simply not worth the trouble.
Alfonso
on 30 Jun 2018
Walter Roberson
on 30 Jun 2018
Perhaps it is only one particular one of the dimensions that needs to be positive and you can divide by the sign of that particular dimension?
Note: your comments are reversed above, R is the eigenvectors and diag(N) are the eigenvalues.
Alfonso
on 30 Jun 2018
Walter Roberson
on 30 Jun 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
on 1 Jul 2018
Accepted Answer
More Answers (0)
Categories
Find more on Process Point Clouds in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


