views:

179

answers:

1

I feel like I should know this, but somehow I'm drawing a blank for the last 30 minutes...

How would one go plotting a plane in matlab or scipy from a normal vector and a point? I keep wanting to use the symbolic math solver, but I don't have the license for it currently... :\

Sorry if this is really basic, my brain just isn't working today it seems

+2  A: 

For Matlab:

point = [1,2,3];
normal = [1,1,2];

%# a plane is a*x+b*y+c*z+d=0
%# [a,b,c] is the normal. Thus, we have to calculate
%# d and we're set
d = -point*normal'; %'# dot product for less typing

%# create x,y
[xx,yy]=ndgrid(1:10,1:10);

%# calculate corresponding z
z = (-normal(1)*xx - normal(2)*yy - d)/normal(3);

%# plot the surface
figure
surf(xx,yy,z)
Jonas
Oh wow, I never knew there even was a ndgrid function. Here I was jumping through hoops with repmat and indexing to create them on the fly all this time haha. Thanks! **Edit:** btw would it be z = -normal(1)*xx - normal(2)*yy - d; instead?
Xzhsh
@Xzhsh: oops, yes. Fixed.
Jonas
@Jonas, also divide by normal(3) ;). Just in case someone else looks at this question and gets confused
Xzhsh
@Xyhsh: well, looks like you're not the only one whose brain isn't working :)
Jonas

related questions