CS2013
CS2013

Reputation: 133

Plot a 3D-plane in Matlab?

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

Consider the plane equation

Z=(-a * X - b * Y)/c

with following coefficients:

a=0.01; b=0.03; c= 1; d=0.

I want to plot this plane around point (100,100) not at origin (0,0). How it possible to do that?

The code I used:

[X,Y] = meshgrid(x);
a=0.1;
b=0.2;
c=1;
d=0;
Z=(-a * X - b * Y)/c;
surf(X,Y,Z)
shading flat
xlabel('x')
ylabel('y')
zlabel('z')

Upvotes: 0

Views: 2250

Answers (1)

Notlikethat
Notlikethat

Reputation: 20914

surf() just plots whatever set of points you give it. To generate those points, you're evaluating the equation at a specific set of coordinates given by X and Y. Therefore you want those points to be centred around the region of interest:

[X, Y] = meshgrid(95:0.1:105);  % e.g. +/-5 at resolution of 0.1

or, say, for arbitrary view coordinates m,n:

[X, Y] = meshgrid(m-20:m+20, n-20:n+20);  % e.g. +/-20 at resolution of 1

That gives you the view around 100,100 of a plane centred at the origin, which I think is what you're asking for.

Alternatively if you want the plane itself centred at 100,100, then you need that offset in the equation:

Z=(-a * (X - 100) - b * (Y - 100))/c;

so then a view centred on the origin will be equivalent to viewing the original plane around -100,-100.

Upvotes: 3

Related Questions