How to convert local coordinate to Global Coordinate of a 3d plane?

8 次查看(过去 30 天)
Hi,
I have a 3d plane with equation: z+0.898x-0.443y=452, I got this equation by plane fit. This plane is inclined at a crazy angle and I want to make one of the point to origin and then make it flat and coincide it one of the axis (mostly x or y). My approach for doing this is first to translate one of the corner point to origin (which is working well I think) and then rotate plane about x-axis to make it parallel to xy-plane. and then give it one more rotation depending on situation.
For rotation, I find direction cosines of the plane and then rotate it by applying rotation matrix about x-axis. But its not working well. Could any one suggest what I am doing wrong or is there any better approach to do this. Figures of my original plane, translated plane and rotated plane about x and y axis are attached. My code is given below:
arr = step_mask('Sigle_Step_Aug23-2017.xlsx','Sheet1', 'A:C');
x=arr(:,1); y=arr(:,2); z=arr(:,3);
% plane fitting
[xnum,ynum]=size(arr);
B = [arr(:,1:2), ones(xnum,1)] \ arr(:,3);
a=B(1);
b=B(2);
d=B(3);
Z=a*x+b*y+d;
[row,col]=size(Z);
c=1;
dist=sqrt(a^2+b^2+c^2);
% calculation of direction cosines
l=-a/dist; %cx
m=-b/dist; %cy
n=c/dist;% cz
% calculation of angle
alfa=acosd(l); % w.r.t x-axis
beta=acosd(m); %w.r.t. y-axis
gamma=acosd(n); %w.r.t. z-axis
A=zeros(row,3);
A(:,1)=x;
A(:,2)=y;
A(:,3)=Z;
% Translation Matrix
A_trans=zeros(4,row);
tx=12.87606300000000025818280846579; ty=28.084973999999998994780980865471; tz=-450.70078850208750509409583173692;
T=[1 0 0 tx; 0 1 0 ty; 0 0 1 tz; 0 0 0 1];
R1=[1 0 0 0; 0 cos_alfa -sin_alfa 0; 0 sin_alfa cos_alfa 0; 0 0 0 1];
%rotation about x-axis
R1=[1 0 0 0; 0 cosd(-alfa) -sind(-alfa) 0; 0 sind(-alfa) cosd(-alfa) 0; 0 0 0 1];
% rotation about y-axis
R2=[cosd(beta) 0 sind(beta) 0; 0 1 0 0; -sind(beta) 0 cosd(beta) 0; 0 0 0 1];
for i=1:row
%A_trans(:,i)=T*R1*[A(i,1);A(i,2);A(i,3);1];
A_trans(:,i)=T*R1*R2*[A(i,1);A(i,2);A(i,3);1];
end
figure;
plot3(A_trans(1,:),A_trans(2,:),A_trans(3,:),'.b'); grid on;
xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');
set(gca, 'FontName', 'Arial');
set(gca, 'FontSize', 12);
title('Translated Plot', 'fontsize', 20);

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by