找回密码
 注册
Simdroid-非首页
查看: 589|回复: 23

三维表面图的画法简介

[复制链接]
发表于 2010-6-23 19:50:45 | 显示全部楼层 |阅读模式 来自 湖北武汉
本帖最后由 alexqxp 于 2010-6-23 19:56 编辑

很多时候我们需要表现的变量维数超过了二维,比如三维,如果直接画成二维图的画,相互关系难以看清楚,如tu2。

要想在一张图里面表现出所有的数据,就需要用到三维表面图。
比如研究两个变量因素下的结果,数据如tu1所示。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 发表于 2010-6-23 19:53:25 | 显示全部楼层 来自 湖北武汉
Simdroid开发平台
可以使用程序
load data;
x=data(:,1);
y=data(:,2);
z=data(:,3);
[X,Y] = meshgrid(x,y);
Z = griddata(x,y,z,X,Y);
surf(X,Y,Z);
camlight right;
lighting phong;
shading interp;
title '磨痕深度-时间-添加剂含量关系图'
ylabel('添加剂含量');
xlabel('时间');
zlabel('磨痕深度');
colorbar;
回复 不支持

使用道具 举报

 楼主| 发表于 2010-6-23 19:58:46 | 显示全部楼层 来自 湖北武汉
本帖最后由 alexqxp 于 2010-6-23 21:20 编辑

当然,数据data必须先变成三维的,如x,y,z
也就是将原始数据变为
回应lengyunfeng ,将数据变化过程用图表示一下。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

 楼主| 发表于 2010-6-23 20:12:53 | 显示全部楼层 来自 湖北武汉
本帖最后由 alexqxp 于 2010-6-23 21:01 编辑

由于数据没有拟合平滑,数据量比较少,图不是太好看。要好看就得进行平滑处理。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

发表于 2010-6-23 20:51:21 | 显示全部楼层 来自 四川成都
本帖最后由 lengyunfeng 于 2010-6-23 20:57 编辑

秦老师,您的由图像入手学Matlab是我进坛子来看的和回复的第一个贴子,心中非常敬仰。希望您以后能多多进坛子泡泡,让我们也近墨者黑一下:lol
对于您的这个贴子,个人觉得自变量有两个,分别为time(0,6,30,60,120,180,980)和添加剂含量(0,1%,2%,3%),tu2中的row2,col2到row8,col5全是函数值,表面图中的数据点应该有4*7=28个之多,和您在3楼列出的数据有一定的出入(不仅是数量上的,还有数值上的);还有shading interp这条语句不是已经有显示上的拟合平滑在里面了吗?个人觉得是数据量太少了才导致图形不好看。另外,有个问题想请教一下,正如您的这个例子,time的变幅要比添加剂含量变幅要大,那么在画图的时候就不大适合用axis equal语句,否则出来的图就会像一块板一样,一个方向短得可怜,一个方向又长得吓人。有没有一个图像处理方面比较通用的方法来处理这一问题呢?还是仅仅只是按个人喜好或者按图形显示美观程度来调整x,y,z的显示比例?看您的语句,是直接让Matlab自动调整x,y,z的显示比例,可是这样也未必就是最好看的,您碰到这种情况又是怎么处理的呢?
回复 不支持

使用道具 举报

 楼主| 发表于 2010-6-23 21:03:52 | 显示全部楼层 来自 湖北武汉
本帖最后由 alexqxp 于 2010-6-23 21:05 编辑

好看也有代价,由于拟合过度了,数据出现了负值,这是不应该有的。说明拟合过程不对。解决的办法一是重新进行拟合处理,达到正确性与美观的统一,就目前这个数据量来说,比较困难。最后选择还是先保证准确性。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

 楼主| 发表于 2010-6-23 21:08:27 | 显示全部楼层 来自 湖北武汉
本帖最后由 alexqxp 于 2010-6-23 21:12 编辑

拟合函数简介
ContentsTopographic data
Fitting a trigonometric surface
The trig surface with highly different scalings on the x and y axes
Fitting the "peaks" surface
Using tiles in gridfit

% Gridfit demo script

% This script file is designed to be used in cell mode
% from the matlab editor, or best of all, use the publish
% to HTML feature from the matlab editor. Older versions
% of matlab can copy and paste entire blocks of code into
% the Matlab command window.

Topographic dataload bluff_data;
x=bluff_data(:,1);
y=bluff_data(:,2);
z=bluff_data(:,3);
% Two ravines on a hillside. Scanned from a
% topographic map of an area in upstate New York.
plot3(x,y,z,'.')


% Turn the scanned point data into a surface
gx=0:4:264;
gy=0:4:400;
g=gridfit(x,y,z,gx,gy);
figure
colormap(hot(256));
surf(gx,gy,g);
camlight right;
lighting phong;
shading interp
line(x,y,z,'marker','.','markersize',4,'linestyle','none');
title 'Use topographic contours to recreate a surface'

Fitting a trigonometric surfaceclear

n1 = 15;
n2 = 15;
theta = rand(n1,1)*pi/2;
r = rand(1,n2);

x = cos(theta)*r;
y = sin(theta)*r;
x=x(:);
y=y(:);

x = [[0 0 1 1]';x;x;1-x;1-x];
y = [[0 1 0 1]';y;1-y;y;1-y];
figure
plot(x,y,'.')
title 'Data locations in the x-y plane'


z = sin(4*x+5*y).*cos(7*(x-y))+exp(x+y);

xi = linspace(0,1,51);
[xg,yg]=meshgrid(xi,xi);
zgd = griddata(x,y,z,xg,yg);

figure
surf(xi,xi,zgd)
colormap(hot(256))
camlight right
lighting phong
title 'Griddata on trig surface'
% Note the wing-like artifacts along the edges, due
% to the use of a Delaunay triangulation in griddata.


zgrid = gridfit(x,y,z,xi,xi);

figure
surf(xi,xi,zgrid)
colormap(hot(256))
camlight right
lighting phong
title('Gridfit to trig surface')

The trig surface with highly different scalings on the x and y axesxs = x/100;
xis = xi/100;

ys = y*100;
yis = xi*100;

% griddata has problems with badly scaled data
[xg,yg]=meshgrid(xis,yis);
zgd = griddata(xs,ys,z,xg,yg);

figure
surf(xg,yg,zgd)
colormap(hot(256))
camlight right
lighting phong
title 'Serious problems for griddata on badly scaled trig surface'

% autoscaling on (the default)
zgrids = gridfit(xs,ys,z,xis,yis,'autoscale','on');

% plot the autoscaled result
figure
surf(xis,yis,zgrids)
colormap(hot(256))
camlight right
lighting phong
title 'Gridfit (automatically scaled) on trig surface'

Warning: Duplicate x-y data points detected: using average of the z values.

  Fitting the "peaks" surfaceclear

n = 100;
x = (rand(n,1)-.5)*6;
y = (rand(n,1)-.5)*6;

z = peaks(x,y);

xi = linspace(-3,3,101);
zpgf = gridfit(x,y,z,xi,xi);

[xg,yg]=meshgrid(xi,xi);
zpgd = griddata(x,y,z,xg,yg,'cubic');

figure
surf(xi,xi,zpgd)
colormap(jet(256))
camlight right
lighting phong
title 'Griddata (method == cubic) on peaks surface'

figure
surf(xi,xi,zpgf)
colormap(hsv(256))
camlight right
lighting phong
title('Gridfit to peaks surface')

  Using tiles in gridfit% Users of gridfit who have really huge problems now have
% an option. I'll generate a large amount of data,
% and hope to model a fairly large grid - 800 x 800. This
% would normally require gridfit to solve a system of
% equations with 640,000 unknowns. It would probably be too
% large of a problem for my computer, were I to use gridfit
% on the full problem. Gridfit allows you to break the problem
% into smaller tiles if you choose. In this case each tile
% is 120x120, with a 25% (30 element) overlap between tiles.

% Relax, this demo may take a couple of minutes to run!!!!

n = 100000;
x = rand(n,1);
y = rand(n,1);
z = x+y+sin((x.^2+y.^2)*10);

xnodes = 0:.00125:1;
ynodes = xnodes;

[zg,xg,yg] = gridfit(x,y,z,xnodes,ynodes,'tilesize',120,'overlap',0.25);

surf(xg,yg,zg)
shading interp
colormap(jet(256))
camlight right
lighting phong
title 'Tiled gridfit'


Published with MATLAB® 7.0.1

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

 楼主| 发表于 2010-6-23 21:35:06 | 显示全部楼层 来自 湖北武汉
本帖最后由 alexqxp 于 2010-6-23 21:36 编辑
秦老师,您的由图像入手学Matlab是我进坛子来看的和回复的第一个贴子,心中非常敬仰。希望您以后能多多进坛子泡泡,让我们也近墨者黑一下:lol
对于您的这个贴子,个人觉得自变量有两个,分别为time(0,6,30,60, ...
lengyunfeng 发表于 2010-6-23 20:51

关于数据我把处理过程附录上了。
关于图形的比例问题,从实际情况来看,由于实验数据的条件限制,变量的变化范围往往相差很大,确实难以有通用的确定比例来解决这个问题。
那么可以考虑人为控制,控制到什么程度比较好呢?应该先保证其大小能够被眼睛比较清楚地看到为起始要求,进而调整到比较美观的比例。
从科学计算可视化的要求来说,对数据进行可视化是为了给人看的,让人通过视觉来对数据进行判断的。
我们遇到的问题是要同时用高倍数的显微镜和低倍数的显微镜来看同一物体,在某一方向上物体有细节,可以经得起高倍数的显微镜看,而在另一方向上没有细节,无法用高倍数的显微镜看,数据就那么多,我们无法无中生有。
回复 不支持

使用道具 举报

发表于 2010-6-24 16:43:19 | 显示全部楼层 来自 贵州贵阳
请问,data在哪里啊?可以附上来吗?
回复 不支持

使用道具 举报

 楼主| 发表于 2010-6-24 17:56:21 | 显示全部楼层 来自 湖北武汉
三楼里面就是data,就是左边的三列数据。
回复 不支持

使用道具 举报

发表于 2010-6-24 17:58:21 | 显示全部楼层 来自 新疆乌鲁木齐
光照和相机命令值得初学者借鉴:先绘制出好看的图形培养下兴趣在说。
  1. camlight right
  2. lighting phong
复制代码
回复 不支持

使用道具 举报

发表于 2010-6-26 20:25:58 | 显示全部楼层 来自 吉林长春
原来我下载的gridfit函数是这里的?
回复 不支持

使用道具 举报

发表于 2010-6-28 23:10:42 | 显示全部楼层 来自 北京海淀
同意“由于数据没有拟合平滑,数据量比较少,图不是太好看。要好看就得进行平滑处理”
感谢大家的支持,我会更加努力的,帮大家找些新的资料的,谢谢
回复 不支持

使用道具 举报

发表于 2010-7-1 16:19:35 | 显示全部楼层 来自 江苏徐州
学习了~~~~~~~~~~~··
回复 不支持

使用道具 举报

发表于 2010-7-4 18:33:06 | 显示全部楼层 来自 湖南长沙
学习,早就想做用MATLAB做个曲面了,谢谢老师!
回复 不支持

使用道具 举报

发表于 2010-7-5 04:38:11 | 显示全部楼层 来自 北京
谢谢大大。。。。。。。
回复 不支持

使用道具 举报

发表于 2010-7-5 11:43:03 | 显示全部楼层 来自 上海
嗯 3Q 我想要得到像gridfit_demo_08.png这样的图形。
回复 不支持

使用道具 举报

发表于 2010-7-5 20:19:16 | 显示全部楼层 来自 德国
借此帖人气,向alexqxq,bainhome等诸位大大请教衍生的问题。谢谢!
在生成了上述两个表面后,研究其接触问题,求相交点。如果对表面进行函数拟合,再求导...这样算是否可行,误差大吗?
回复 不支持

使用道具 举报

发表于 2010-7-5 21:20:19 | 显示全部楼层 来自 新疆乌鲁木齐
18# Melvin1231
此类问题没有搞过,,不过曲面的函数拟合在MATLAB中也许可以通过样条工具箱中的一些函数完成,例如B样条的拟合再求导精度是很不错的。此类主题在版面里有一些。自己也可以查一下样条工具箱中的help。
回复 不支持

使用道具 举报

发表于 2010-7-6 08:56:46 | 显示全部楼层 来自 湖南长沙
哪位能用这里面的数据做个曲面?谢谢,很想学这个!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-28 15:13 , Processed in 0.053254 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表