声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 8961|回复: 18

[绘图技巧] 如何有三维数据画曲面??

[复制链接]
发表于 2008-5-21 08:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
现在有一组数据 分别为x=[1 2 3 4 5 6 7 8 9];
y=[5 6 7 8 9 10 11 12 13 ]
z=[14 15 16 17 18 19 20 21 22 ]
现在要画一曲面图形 坐标分别为x y z
这里的数据个数 可以增加为了方便我只写了几个,但有一点是确定的 就是 X Y每个数据之间的间隔不是确定的 。 但xyz三个数据是相对应的 .即有一个XY就有一个Z与之对应,但这个关系未知,只是有这样一个对应关系,现在要通过这些离散的数据 得到一曲面图,
希望大家能帮我想一下怎么处理。
当用到GRIDDATA MESH 等这些命令的时候 渴望得到你的具体例子的解释。比如说 最好针对如题所示的数据。
谢谢大家了
回复
分享到:

使用道具 举报

发表于 2008-5-21 08:50 | 显示全部楼层
以你这样的数据是画不出来曲面的,只能是一条曲线。
画曲面的数据应该是(x(i),y(j),z(i,j))而不是你提供的这种(x(i),y(i),z(i))
发表于 2008-5-21 09:16 | 显示全部楼层
help  griddata
发表于 2008-5-21 09:25 | 显示全部楼层

回复 楼主 的帖子

赞同主任的方法,
有一个XY就有一个Z与之对应,但这个关系未知,这样很难得到.
因为你做曲面图,首先生成的是平面上的点的x,y坐标,事实上这个坐标就是你所列的数组x,y中分别取一个得到的组合.所以平面坐标已经扩展到length(x)*length(y)个了,而你的z得到的只是里面一条曲线的值.
一般如果知道xy同z关系的话,问题就很好解决. 给出一般方法:
x=[1 2 3 4 5 6 7 8 9];
y=[5 6 7 8 9 10 11 12 13 ];
[X,Y]=meshgrid(x,y);
Z=f(X,Y);% Z同XY之间的关系和z同x,y之间的关系一样
mesh(X,Y,Z);
发表于 2008-5-21 09:31 | 显示全部楼层
GRIDDATA Data gridding and surface fitting.
    ZI = GRIDDATA(X,Y,Z,XI,YI) fits a surface of the form Z = F(X,Y) to the
    data in the (usually) nonuniformly-spaced vectors (X,Y,Z). GRIDDATA
    interpolates this surface at the points specified by (XI,YI) to produce
    ZI.  The surface always goes through the data points. XI and YI are
    usually a uniform grid (as produced by MESHGRID) and is where GRIDDATA
    gets its name.

    XI can be a row vector, in which case it specifies a matrix with
    constant columns. Similarly, YI can be a column vector and it specifies
    a matrix with constant rows.

    [XI,YI,ZI] = GRIDDATA(X,Y,Z,XI,YI) also returns the XI and YI formed
    this way (the results of [XI,YI] = MESHGRID(XI,YI)).

    [...] = GRIDDATA(X,Y,Z,XI,YI,METHOD) where METHOD is one of
        'linear'    - Triangle-based linear interpolation (default)
        'cubic'     - Triangle-based cubic interpolation
        'nearest'   - Nearest neighbor interpolation
        'v4'        - MATLAB 4 griddata method
    defines the type of surface fit to the data. The 'cubic' and 'v4'
    methods produce smooth surfaces while 'linear' and 'nearest' have
    discontinuities in the first and zero-th derivative respectively.  All
    the methods except 'v4' are based on a Delaunay triangulation of the
    data.
    If METHOD is [], then the default 'linear' method will be used.

    [...] = GRIDDATA(X,Y,Z,XI,YI,METHOD,OPTIONS) specifies a cell array
    of strings OPTIONS to be used as options in Qhull via DELAUNAYN.
    If OPTIONS is [], the default DELAUNAYN options will be used.
    If OPTIONS is {''}, no options will be used, not even the default.

    Example:
       rand('seed',0)
       x = rand(100,1)*4-2; y = rand(100,1)*4-2; z = x.*exp(-x.^2-y.^2);
       ti = -2:.25:2;
       [xi,yi] = meshgrid(ti,ti);
       zi = griddata(x,y,z,xi,yi);
       mesh(xi,yi,zi), hold on, plot3(x,y,z,'o'), hold off
发表于 2008-5-21 09:40 | 显示全部楼层
  1. >> x=[1 2 3 4 5 6 7 8 9];
  2. >> y=[5 6 7 8 9 10 11 12 13 ];

  3. >> z=[14 15 16 17 18 19 20 21 22 ];

  4. >> xi=linspace(1,10);
  5. >> yi=linspace(5,15);
  6. >> [X,Y]=meshgrid(xi,yi);
  7. >> Z=griddata(x,y,z,X,Y,'v4');
  8. >> mesh(X,Y,Z)
  9. >> hold on;
  10. >> plot3(x,y,z,'o')
复制代码



不过,你的点基本都在一条曲线上,所以画面,很不合适
untitled.jpg

评分

1

查看全部评分

发表于 2008-5-21 13:46 | 显示全部楼层
非常不错的论坛,学到很多东西。
发表于 2008-7-6 18:34 | 显示全部楼层
我这里有个关于海螺的曲面的点的数值,但是按上面的方法做出来的结果不对,请问是否应该做一些其他的改动才行,今天才发现这个论坛,这里的互动回答特别让我感动,希望哪位能给指点一下,数据是用txt文件保存的,但是我发现我不能用附件上传功能,是哪里出问题了吗,如果需要数据,我可以用邮箱发,我的邮箱:xinxin7311@163.com,谢谢
发表于 2008-7-6 19:24 | 显示全部楼层

回复 8楼 的帖子

只改坐标
发表于 2008-7-7 07:23 | 显示全部楼层
坐标是改了,但做出来的结果和原始模型差太远,我无法把得到的图形粘贴上来,总之和原来模型的海螺根本不是一回事,数据太多无法发送,请问怎么样在回复时用附件上传啊?谢谢
>> load d:\seashell.txt;
>> x=seashell(:,1);
>> y=seashell(:,2);
>> z=seashell(:,3);
>> xi=linspace(1,10);
>> yi=linspace(5,15);
>> [X,Y]=meshgrid(xi,yi);
>> Z=griddata(x,y,z,X,Y,'v4');
Warning: Duplicate x-y data points detected: using average of the z values.
> In griddata at 105
>> mesh(X,Y,Z)
发表于 2008-7-7 09:24 | 显示全部楼层
Z=griddata(x,y,z,X,Y,'v4');
help griddata 可以选择不同的方法,这里的'v4'可以换成其他的
如过还不行,可能你的数据分布太不均匀了
ps:附件上传点 “发表新回复”,下面有 “上传附件”的
发表于 2008-7-7 15:00 | 显示全部楼层

谢谢小西的回复,问题仍没解决

我试了各种插值方式,但是在求Z时总是提示:Warning: Duplicate x-y data points detected: using average of the z values,在搜索里也没找到相应的解决办法,我两天把300多页的相关帖子都简单浏览了一遍,也不知道该怎么做,只好继续向你讨教。谢谢

seashell.txt

26.67 KB, 下载次数: 8

发表于 2008-7-7 15:10 | 显示全部楼层
这是模型本来的形状
image10.gif
发表于 2008-7-7 18:12 | 显示全部楼层

回复 13楼 的帖子

可能是你数据排列顺序有问题

Duplicate x-y  重复?
发表于 2008-7-7 21:05 | 显示全部楼层
我查过了,x和y的数据是不重复的,所以对这个错误很不理解,而且换了另外一个文件的数据也不行,还是这个错误
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-17 16:57 , Processed in 0.075180 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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