MATLAB Answers

pablo
0

rotate 3D plane to a new 2d coordinate system

Asked by pablo
on 10 Jul 2013
Latest activity Edited by Johannes on 10 Jan 2018
Hello, I have been looking for this relatively simple issue but I haven't found a simple solution.
I have extracted a plane in 3D from a visualization software, so I have a matrix of coordinates: Coor_3D= [x1 x2 x3];.
As all the points are lying on the same plane, I was wondering how can I transform the above matrix to obtain a simple one in 2D, i.e = Coor_2D=[x1' x2' 0];
Thanks

  0 Comments

Sign in to comment.

3 Answers

Answer by Matt Kindig on 10 Jul 2013
 Accepted Answer

Simplest way is just using a transformation matrix.
%assume points are Nx3, where N is number of points.
%let first point origin in 2D coordinate system (can be shifted later)
%Calculate out-of-plane vector (local z)
N = size(Coor_3D,1);
origin = Coor_3D(1,:);
localz = cross(Coor_3D(2,:)-origin, Coor_3D(3,:)-origin);
%normalize it
unitz = localz/norm(localz,2);
%calculate local x vector in plane
localx = Coor_3D(2,:)-origin;
unitx = localx/norm(localx,2);
%calculate local y
localy = cross(localz, localx);
unity = localy/norm(localy,2);
%assume transformation matrix
T = [localx(:), localy(:), localz(:), origin(:); 0 0 0 1];
C = [Coor_3D, ones(N,1)];
Coor_2D = T \ C';
Coor_2D = Coor_2D(1:3,:)';

  4 Comments

Show 1 older comment
T = [localx(:), localy(:), localz(:), origin(:); 0 0 0 1]; should be T = [unitx(:), unity(:), unitz(:), origin(:); 0 0 0 1]; right?
Homogeneous Transformation.And Hazen comment is correct.
But your output(Coor_2D) is still 3D!! so the 2D matrix will be [unitx unity]?

Sign in to comment.


Answer by Matt J
on 10 Jul 2013
Edited by Matt J
on 10 Jul 2013
 Accepted Answer

Once you decide on a target plane, find the axis where the targe tplane intersects your current plane. Then rotate around that axis using

  0 Comments

Sign in to comment.


Answer by Elena Figal on 9 Jan 2018

Hello, I tried to recover the original 3D points from the transformation by using the same matrix T and a set of 2D points with a rows of zero and a row of 1, but my new 3D points are different from the originals, could you please help me?

  1 Comment

I want to know the same: Please open a new issue and let's see if someone finds the answer. Please let me know if you find something.
I am this far now:
Matt kindig does:
T = [unitx(:), unity(:), unitz(:), origin(:); 0 0 0 1];
C = [pnts, ones(N,1)]
Coor_2D = T \ C'
To recover pnts out of Coor_2D, you have to solve the equation for C and then extract pnts. I think it should be:
C = (T*Coor_2D)'
But this does not result in the correct points...any other idea?
Edit: I found the solution!
My mathematical solution was right, you just have to handle Coor_2D correctly to transform it backwards. Here's the code. You just need 2d-points (twoDpnts), the Transformation T and a row of zeros (zeros(size(twoDpnts,1)) and a row of ones (ones(size(twoDpnts,1),1)).
Coor_2D_backwards = [twoDpnts zeros(size(twoDpnts,1),1) ones(size(twoDpnts,1),1)]'
C = (T*Coor_2D_backwards)'
pnts = C(:,1:3)
Best regards

Sign in to comment.