Plotting a plane normal to a vector and passing through a point

I'm relatively new to MATLAB and am trying to work through a process for plot a plane normal to a specified vector and that passes through a specified point. Here is my approach substituting artificial values in for coordinates:
A=[... ... ...] dimensions of A are 512x512x11 and A represents a 3D matrix of values
% Read in XYZ coordinates for point #1
pt1=[1,2,1];
% Read in XYZ coordinates for point #2
pt2=[3,6,1];
% Plot a line connecting these two points
plot3([pt1(1);pt2(1)],[pt1(2);pt2(2)],[pt1(3);pt2(3)]);
% Choose a point #3 along the line where point of interest is
pt3=[2,4,1];
% Create a vector that originates from point #1 and extends to point #2
n=[(pt1(1)-pt2(1)) (pt1(2)-pt2(2)) (pt1(3)-pt2(3))];
% Create a plane orthogonal to vector at point #3
array=zeros(512,512,numFrames);
figure
for a=1:512
for b=1:512
for c=1:numFrames
if n(1)*(a-pt3(1))+n(2)*(b-pt3(2))+n(3)*(c-pt3(3))==0
array(a,b,c)=A(a,b,c);
plot3(a,b,c)
hold on
end
end
end
end
---------
this runs off the scalar equation of the plane through point P0(x0,y0,z0), called point #3 above, with normal vector n=<a,b,c>:
a*(x-x0)+b*(y-y0)+c*(z0-z)=0
Right now the output is a series of points in the z-direction at point #3; whereas I was expecting to generate a plane that satisfied the above equation. Any feedback or comments would be appreciated. Thank you,

 Réponse acceptée

I was able to come up with my own answer for this. For others looking to do the same, I would suggest modifying the code the following way:
if abs(n(1)*(a-pt3(1))+n(2)*(b-pt3(2))+n(3)*(c-pt3(3)))<1
Due to the size of the 3-D matrix A being rather coarse, 512x512X11, setting the original statement ==0 would only likely include a single stack of points in a column instead of a plane. By increasing the value, the width of the plane increases to encompass and capture more points that can be displayed.
Hope this is helpful...

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by