matlab 绘制三维空间隐函数自由曲面

1.简介

本博客介绍了一个常用于三维隐函数绘制的函数,利用自由曲面-球面为事例,介绍该函数的用法。
本功能实现主要的两个函数
isofurface
patch
其实主要是第一个函数有用

2.isosurface介绍

matlab2014a 版给的函数介绍:
isosurface Isosurface extractor.
  FV = isosurface(X,Y,Z,V,ISOVALUE) computes isosurface geometry for
  data V at isosurface value ISOVALUE. Arrays (X,Y,Z) specify the points
  at which the data V is given. The struct FV contains the faces and
  vertices of the isosurface and can be passed directly to the PATCH
  command.
  
  FV = isosurface(V,ISOVALUE) assumes [X Y Z] = meshgrid(1:N, 1:M, 1:P)
  where [M,N,P]=SIZE(V).
  
  FV = isosurface(X,Y,Z,V) or FV = isosurface(V) selects an
  isosurface value automatically using the histogram of the
  data.
  
  FVC = isosurface(…, COLORS) interpolates the array COLORS onto
  the scalar field and returns the interpolated values in
  facevertexcdata. The size of the COLORS array must be the same
  as V.
  
  FV = isosurface(…, ‘noshare’) does not attempt to create
  shared vertices. This is faster, but produces a larger set of
  vertices.
  
  FV = isosurface(…, ‘verbose’) prints progress messages to the
  command window as the computation progresses.
  
  [F, V] = isosurface(…) or [F, V, C] = isosurface(…)
  returns the faces and vertices (and facevertexcdata) in
  separate arrays instead of a struct.
  
  isosurface(…) With no output arguments, a patch is created
  into the current axes with the computed faces and vertices.
  If no current axes exists, a new axes will be created with
  a 3-D view and appropriate lighting.

简而言之
isosurface适用于三维隐函数图像的绘制。
简单用法isosurface(x,y,z,v,isovalue);
其中v是关于网格数据x,y,z的体数据,isovalue是对应于v的水平基下的关联数据,
也就是v=? 可以看下面例子更好理解;

3.画球

空间画球很简单
球面方程 x^2 + y^2 + z^2 = R^2 = 1 以单位球为例子

% code by Coom
[x,y,z] = meshgrid(-1:0.1:1); % 设置范围
f = (x.^2+y.^2+z.^2 - 1); % 球面方程
p = patch(isosurface(x,y,z,f,0)); %隐函数绘图
set(p,'FaceVertexCData',jet(size(get(p,'faces'),1)) ,'FaceColor', 'flat', 'EdgeColor', 'black'); %设置显示样式
view(3);
axis equal;
grid on;

在这里插入图片描述

4.后续更改和自定义绘图

由于可能黑边可能不能满足一些论文图片,需要进行更改。
涉及到这个问题首先就要清楚一些matlab中颜色的信息。
首先jet这些,
在这里插入图片描述

上面颜色组信息是matlab内置的颜色组,在上面画球使用的便是jet组。颜色组可以随意更改
为了更为直观的阐述作用
将上述函数改为

% code by Coom
% code by Coom
[x,y,z] = meshgrid(-1:0.1:1);
f = (x.^2+y.^2 +z.^2- 1);
[ff,vv]= isosurface(x,y,z,f,0);
p=patch('Faces',ff,'Vertices',vv,'CData',vv(:,3),'facecolor','flat','EdgeColor','black','edgealpha',0.1)
% set(p,'FaceVertexCData',jet(size(get(p,'faces'),1)) ,'FaceColor', 'flat', 'EdgeColor', 'black');
view(3);
axis equal;
grid on;

其中的属性
facecolor 表示面颜色 可以设置flat,或者其他的颜色,‘b’-蓝色,‘r’-红色用法和plot中的颜色设置一样
edgecolor 表示边颜色,如果觉得黑边不好看,可以换成任意颜色,也可以设置成flat,设置成none删掉边颜色,任意颜色的设置可以利用矩阵来设置,[0 0 0]表示黑色 [1 1 1]表示白色
此外还可以从上面看出
另外一种自定义属性为是edgealpha 是设置透明度的,0为完全透明,1为完全不透明。下面是黑边0.1的透明度效果。更多功能需要自定义组合来看

此外,欢迎关注公众号 ‘一匹大懒虫’ ,里面有一些软件资源和matlab基础教程,以及写的代码和相关文档。在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CoomCon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值