How do I create a 3D surface with points of data in MATLAB 6.5 (R13)?
9 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2009-6-27
编辑: MathWorks Support Team
2020-8-3
I have a set of data that are sampled from the outer walls of a spherical object. I would like to create a 3D object that I can rotate and translate.
采纳的回答
MathWorks Support Team
2009-6-27
You can create 3D surface with points of data by using the DELAUNAY3 and TRISURF functions as shown in the example code below:
load data;%You can find the data MAT-file in the resolution documents
%Extract the X, Y and Z coordinates
X=M(:,1);
Y=M(:,2);
Z=M(:,3);
%Generate the surface
T=delaunay3(X,Y,Z);
%Create and apply the colormap
c = zeros(64,3);
for i = 1:64
c(i,1) = .5;%(i+32)/100;
c(i,2) = 0;%i/100;
c(i,3) = 0;%i/100;
end
colormap(c);
%Plot the surface
hObj = trisurf(T,X,Y,Z,'FaceColor','interp','FaceLighting','phong');
shading interp
Please note that if you wish to rotate the object with ROTATE in MATLAB 7.0.1 (R14SP1) or earlier, you cannot use the above code as there is a bug with rotating patches with interpolated shading (see the Related Solution section for more details). However, you can use flat shading with ROTATE instead by using the following commands:
%Plot the surface
hObj = trisurf(T,X,Y,Z,'FaceLighting','phong');
set(hObj,'FaceVertexCData',[1]);
%set(hObj,'edgecolor','none'); % You can turn off the edgecolor as well
set(hObj,'edgecolor',[0.64 0.1 0.1])
rotate(hObj,[1 0 0],180);% Rotate the object on its x-axis by 180 degrees
1 个评论
Sriram Narayanan
2014-4-21
编辑:MathWorks Support Team
2020-8-3
Starting MATLAB 7.9 (R2009b), it is recommended to use "DelaunayTri" function for 3-D surface plot.
The "DelaunayTri" function was removed in R2012b. Therefore, starting MATLAB 8.1 (R2013a), it is recommended to use the "delaunaytriangulation" function instead.
Please refer to the following documentation link that gives an example on how to generate and visualize a 3-D surface.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!