MATLAB Answers


How do I plot a plane that has points of different values?

Asked by Jing Ci Neo on 5 Jul 2018
Latest activity Commented on by Jing Ci Neo on 6 Jul 2018
I have a 16 by 20 set of points on a plane in 3D, which each has x, y and z coordinates and a slip value. I want to plot the plane with colours at each point representing the slip value. How can I do that?


Sign in to comment.




1 Answer

Answer by Anton Semechko on 5 Jul 2018
 Accepted Answer

Actually, based on the sample picture you provided, you have a total of 17x21 grid points, and total number of cells in the grid is 16x20. You can use 'patch' function to obtain visualization similar to your sample image. Here is an example:
% Generate a M-by-N grid
V=[X(:) Y(:)]; % xy-coordinates of the grid-points
% Define connectivity of the inidividual cells making-up the grid
Np=numel(X); % total number of grid points
id=reshape(1:Np,[M+1 N+1]); % grid-point indices
F=[i1(:) i2(:) i3(:) i4(:)];
% Suppose these are the values of a scalar field measured at the grid points
% Simulated grid currently lies in the xy-plane. Lets rotate it to make it
% look more like the grid in your image.
[~,Rz,~,Rx]=xyzRmat(pi*[45 0 30]/180);
% Here is one visualization appoach; values at the grid points will be
% interpolated to the interior of the cells
axis tight
view([30 30])
camlight('headlight'), lighting phong
% Here is another visualization appoach; each grid cell will have a
% constrant value, corresponding to the average of its vertices
axis tight
view([30 30])
camlight('headlight'), lighting phong
'xyzRmat' function used in this example is included as an attachment.


Hello Anton, thank you for the really detailed answer, you're really amazing! I don't really understand the xyzRmat function though. I tried toggling with the inputs and put in ax=90; ay=0; az=0; (updating the code appropriately) but it didn't rotate by 90 degrees about the x axis to become a xz plane as expected. Could you explain the rotation part to me?
'xyzRmat' computes rotation matrices about x-, y-, and z-axes. For example, lets say {Rx,Ry,Rz} are rotation matrices corresponding to rotations of (a_x,a_y,a_z) radians about (x,y,z) axes. You can obtain arbitrary rotations in 3D space using composition of these 3 rotation matrices (i.e., R=Rz*Ry*Rx). Note that the order of multiplication is very important. In this example, a point is first rotated about the x-axis by a_x, then by a_y about the y-axis, and finally by a_z about z-axis. To obtain rotation of 90 degrees (i.e., pi/2 radians) about the x-axis you would use command:
[R,Rz,Ry,Rx]=xyzRmat(pi*[90 0 0]/180);
In this particular case, Rz and Ry will be identity matrices, and resulting rotation matrix will be R = Rz*Ry*Rx = Rx. Applying R to points in xy-plane will map these points to xz-plane, as expected; make sure you are using correct syntax when calling 'xyzRmat'. For example, new coordinates of point (1,1,0) will be:
R=xyzRmat(pi*[90 0 0]/180);
ans =
1 6.12323399573677e-17 1
It's so weird because I typed the exact commands in but it gives a tilted plane (see attached). It's a minor problem (I have what I need already), but I'm curious as to what the problem is.

Sign in to comment.