How to define the Cartesian plane in MATLAB

282 Views Asked by At

I want to define a small plane in which 'x' changes from (0.5 to 49.5), 'y' changes from (0 to 4.8) and 'z' changes from lets say (2.5 to 4.4). Its like a small piece of a pitched roof placed at an angle of about 22 degrees. I want to get the Cartesian points (x,y,z) of each point in this plane to use them later in some formula. Please help!

1

There are 1 best solutions below

0
On BEST ANSWER

How to store the points to represent the plane patch really depends on your upstream and downstream modules.

The mathematical analysis is contained in the comments of the code block, where I deliberately print out some of the intermediate results.

x = [0.5 49.5]; y = [0, 48]; z = [2.5 4.4];
Vx = [x(2) - x(1) 0 z(2) - z(1)];  % vector along x, on the plane
Vy = [0 y(2) - y(1) z(2) - z(1)];  % vector along y, on the plane
Vn = cross(Vx, Vy);  Vn = Vn / norm(Vn) % unit vector normal to the plane patch

% Plane equation is ax + by + cz = d, where [a b c] = Vn
d = Vn * [x(1) y(1) z(1)]' % Solve for d. Inner product

nX = 23; nY = 37; % user input number of grid points
xBase = linspace( x(1), x(2), nX );
yBase = linspace( y(1), y(2), nY );
[xGrid yGrid] = meshgrid( xBase, yBase );
zGrid = d - (Vn(1) * xGrid - Vn(2) * yGrid ) / Vn(3); % Given any [x y] we have z = (d - ax - by)/c

%{ 
The requested 3-dim data is established above. Whether you wan to plot it or do 
some computation is a different matter.
Note the convention of the origin being on the "top left" so that yGrid 
might need flipping for some of the plot functions.
%}
mesh( xGrid, flipud(yGrid), zGrid)  
xlabel('X'); ylabel('Y');  zlabel('Z'); 
axis vis3d  % fix aspect ratio when rotating