Clear Filters
Clear Filters

Plane with line rotation/transformation

2 views (last 30 days)
Kamil
Kamil on 9 Jun 2015
Edited: Walter Roberson on 11 Jun 2015
Hello,
I have set of 3 points which creates a plane. In addition I have a set of two points which create a line. I would like to transform/rotate my plane with line in the way that a new plane will lay on xy plane (z=0). Below, I present my script in Matlab. It seems that it working. I have a good angle between a new plane and a new position of line. However, if I check an angle between my reference plane XY 2x-y=1 the angle is differ.I know they are shifted on z axis but I think the angle should stay the same. Am I right or I miss something? What I am doing wrong? Thank you for any help.
% xy plane z=0
p1 = [2 3]; % Point 1 for the plane
p2 = [1 1]; % Point 2 for the plane
syms x y z
M1 = [x y 1; p1(1) p1(2) 1; p2(1) p2(2) 1]; % Matrix to solve
P1 = vpa(det(M1)); % equation of the plane
D1 = double(subs(P1, {x, y, z}, {0, 0, 0})); % D coeefitient of the plane equation
A1 = double(subs(P1, {x, y, z}, {1, 0, 0}))-D1; % A coeefitient of the plane equation
B1 = double(subs(P1, {x, y, z}, {0, 1, 0}))-D1; % B coeefitient of the plane equation
C1 = double(subs(P1, {x, y, z}, {0, 0, 1}))-D1; % C coeefitient of the plane equation
format short e
P1 = [-37.77 -58.85 -34.67]; % Point 1 for the plane
P2 = [27.53 -61.54 -28.18]; % Point 2 for the plane
P3 = [-58.91 15.29 -50.52]; % Point 3 for the plane
plane_old=[P1; P2; P3];
w = cross(plane_old(2,:)-plane_old(1,:),plane_old(3,:)-plane_old(1,:));
w = w/norm(w);
R = [null(w),w.'];
if det(R)<0, R(:,1:2) = R(:,2:-1:1); end
plane_new = plane_old*R;
P1 = plane_new(1,1:3);
P2 = plane_new(2,1:3);
P3 = plane_new(3,1:3);
syms x y z
M = [x y z 1; P1(1) P1(2) P1(3) 1; P2(1) P2(2) P2(3) 1; P3(1) P3(2) P3(3) 1]; % Matrix to solve
% M = [x y 1; P1(1) P1(2) 1; P2(1) P2(2) 1] % Matrix to solve
P = vpa(det(M)); % equation of the plane
D = double(subs(P, {x, y, z}, {0, 0, 0})); % D coeefitient of the plane equation
A = double(subs(P, {x, y, z}, {1, 0, 0}))-D; % A coeefitient of the plane equation
B = double(subs(P, {x, y, z}, {0, 1, 0}))-D; % B coeefitient of the plane equation
C = double(subs(P, {x, y, z}, {0, 0, 1}))-D; % C coeefitient of the plane equation
Ap = [-19.29 5.57 -15.67]; % Up point
A0 = [ -1.6452e+001 -6.1967e+000 -9.5058e+000]; % Down point
Ap_new = Ap*R;
A0_new = A0*R;
syms t
line = vpa(A0_new + t*(Ap_new-A0_new)) % line equation
a = Ap_new(1)-A0_new(1); % a coeefitient of the line equation
b = Ap_new(2)-A0_new(2); % a coeefitient of the line equation
c = Ap_new(3)-A0_new(3); % a coeefitient of the line equation
angle1 = asin(abs(A*a+B*b+C*c)/(sqrt(A^2+B^2+C^2)*sqrt(a^2+b^2+c^2)))*180/pi % angle between line and plane
angle1 = asin(abs(A1*a+B1*b+C1*c)/(sqrt(A1^2+B1^2+C1^2)*sqrt(a^2+b^2+c^2)))*180/pi % angle between line and plane xy
[X,Y] = meshgrid(-50:.1:50, -50:1:50); % net of the points to draw plane
Z = ((-A.*X-B.*Y-D)./C);
surf(X,Y,Z,'EdgeColor','none','FaceColor','red');
hold on
alpha(0.3)
grid on
Z1 = zeros(101,1001);
surf(X,Y,Z1,'EdgeColor','none','FaceColor','green');
alpha(0.3)
t = linspace(-10,10,10);
plot3(A0_new(1)+t*(Ap_new(1)-A0_new(1)),A0_new(2)+t*(Ap_new(2)-A0_new(2)),A0_new(3)+t*(Ap_new(3)-A0_new(3)),'LineWidth',2,'Color','blue');
plot3(Ap_new(1), Ap_new(2), Ap_new(3),'.','MarkerSize',30,'Color','red');
plot3(A0_new(1), A0_new(2), A0_new(3),'.','MarkerSize',30,'Color','m');
  1 Comment
Sreeja Banerjee
Sreeja Banerjee on 10 Jun 2015
Hi Kamil, Can you please clarify what you mean by "if I check an angle between my reference plane XY 2x-y=1 the angle is differ.". Also it will be helpful if you can give an example on what values you expect and what you are getting.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!