How do I plot a plane that has points of different values?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jing Ci Neo
le 5 Juil 2018
Commenté : Jing Ci Neo
le 6 Juil 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?
0 commentaires
Réponse acceptée
Anton Semechko
le 5 Juil 2018
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
[M,N]=deal(16,20);
x=linspace(-3,3,N+1);
y=linspace(-3,3,M+1);
[X,Y]=meshgrid(x,y);
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
i1=id(1:M,1:N);
i2=id(2:(M+1),1:N);
i3=id(2:(M+1),2:(N+1));
i4=id(1:M,2:(N+1));
F=[i1(:) i2(:) i3(:) i4(:)];
% Suppose these are the values of a scalar field measured at the grid points
Q=sinc(sqrt((X/2).^2+Y.^2))+sinc(sqrt((X).^2+(Y/3).^2));
Q=Q(:);
% 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);
V(:,3)=0;
V2=(Rx*Rz*V')';
% Here is one visualization appoach; values at the grid points will be
% interpolated to the interior of the cells
figure('color','w')
subplot(1,2,1)
patch('Faces',F,'Vertices',V2,'EdgeColor','k','FaceVertexCData',Q,'FaceColor','interp');
set(gca,'box','on')
axis tight
view([30 30])
camlight('headlight'), lighting phong
colorbar('Location','NorthOutside')
% Here is another visualization appoach; each grid cell will have a
% constrant value, corresponding to the average of its vertices
subplot(1,2,2)
patch('Faces',F,'Vertices',V2,'EdgeColor','k','FaceVertexCData',Q,'FaceColor','flat');
set(gca,'box','on')
axis tight
view([30 30])
camlight('headlight'), lighting phong
colorbar('Location','NorthOutside')
'xyzRmat' function used in this example is included as an attachment.
3 commentaires
Anton Semechko
le 6 Juil 2018
Modifié(e) : Anton Semechko
le 6 Juil 2018
'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);
(R*[1;1;0])'
ans =
1 6.12323399573677e-17 1
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!