Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot a 3D-plane in Matlab?

Tags:

I would like to plot a plane using a vector that I calculated from 3 points where:

pointA = [0,0,0]; pointB = [-10,-20,10]; pointC = [10,20,10];  plane1 = cross(pointA-pointB, pointA-pointC) 

How do I plot 'plane1' in 3D?

like image 989
user1834916 Avatar asked Nov 19 '12 23:11

user1834916


People also ask

Which command is for plotting a 3D surface in MATLAB?

surf( X , Y , Z ) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors.


2 Answers

Here's an easy way to plot the plane using fill3:

points=[pointA' pointB' pointC']; % using the data given in the question fill3(points(1,:),points(2,:),points(3,:),'r') grid on alpha(0.3) 

enter image description here

like image 168
bla Avatar answered Sep 19 '22 20:09

bla


You have already calculated the normal vector. Now you should decide what are the limits of your plane in x and z and create a rectangular patch.

An explanation : Each plane can be characterized by its normal vector (A,B,C) and another coefficient D. The equation of the plane is AX+BY+CZ+D=0. Cross product between two differences between points, cross(P3-P1,P2-P1) allows finding (A,B,C). In order to find D, simply put any point into the equation mentioned above:

   D = -Ax-By-Cz; 

Once you have the equation of the plane, you can take 4 points that lie on this plane, and draw the patch between them.

enter image description here

normal = cross(pointA-pointB, pointA-pointC); %# Calculate plane normal %# Transform points to x,y,z x = [pointA(1) pointB(1) pointC(1)];   y = [pointA(2) pointB(2) pointC(2)]; z = [pointA(3) pointB(3) pointC(3)];  %Find all coefficients of plane equation     A = normal(1); B = normal(2); C = normal(3); D = -dot(normal,pointA); %Decide on a suitable showing range xLim = [min(x) max(x)]; zLim = [min(z) max(z)]; [X,Z] = meshgrid(xLim,zLim); Y = (A * X + C * Z + D)/ (-B); reOrder = [1 2  4 3]; figure();patch(X(reOrder),Y(reOrder),Z(reOrder),'b'); grid on; alpha(0.3); 
like image 36
Andrey Rubshtein Avatar answered Sep 17 '22 20:09

Andrey Rubshtein