Converting 3D to 2D cloud of points

조회 수: 19 (최근 30일)
Alfonso
Alfonso 2018년 6월 30일
댓글: Matt J 2018년 7월 4일
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
Walter Roberson
Walter Roberson 2018년 6월 30일
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 2018년 7월 1일
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:

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

채택된 답변

Matt J
Matt J 2018년 6월 30일
편집: Matt J 2018년 6월 30일
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
Alfonso
Alfonso 2018년 7월 4일
Hello Matt, with a few modifications I think I finally got it to work right. Thank you for your help.
Matt J
Matt J 2018년 7월 4일
No problem. Glad you got what you needed.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by