Reputation: 35
I want to plot the plane perpendicular to a vector, and going through a point with Matlab.
My vector has coordinates v1 = [2,i]
and my point has coordinates com_m1 = [1,i]
.
I have tried both:
xx=(-15:-6:0.25);
yy=(-10:-2:0.25);
for i = 1:length(xx)
for j = 1:length(yy)
zz_m1(j,i)=(v1(2,2)*(xx(i) - com1(1,1)) + v1(2,2)*(yy(j)-com1(1,2)))/v1(2,3) + com1(1,3);
end
end
surf(xx,yy,zz_m1, 'FaceColor','red','EdgeColor','none') % Plotting the surface
and
[xx, yy]=meshgrid(-15:-6:0.25,-10:-1:0.25);
zz_m1=(v1(2,2)*(xx - com1(1,1)) + v1(2,2)*(yy-com1(1,2)))/v1(2,3) + com1(1,3);
surf(xx,yy,zz_m1, 'FaceColor','red','EdgeColor','none')
But both didn't work. Can anyone help me understand what I am doing wrong? Thanks!
Upvotes: 1
Views: 2790
Reputation: 20309
There are some problems in your code. The biggest is this line, xx=(-15:-6:0.25);
It produces an empty matrix, as your asking for a vector that starts at -15
and continues on to -Inf
.
If you don't understand the mistake then you should probably read the Colon Notation Docs Your matrix yy
has the same problem as xx
.
Additionally I think your calculations for the plane are incorrect. I tried your code locally using a randomly generated v1
and com1
and the line isn't normal to the plane.
Here is a nice explanation of how to compute the equation for a plane that passes through a point and is perpendicular to a known vector: http://msemac.redwoods.edu/~darnold/math50c/matlab/planes/index.xhtml (scroll down to A Plane is a Surface)
Upvotes: 1