matlab 求解体积,matlab如何计算多面体体积

一个多面体的体积应该如何计算?

这本来是一个比较复杂的问题,应该要用到积分,但在matlab中确实很简单的事情,因为有现成的函数,只要稍微组合一下就可以。

下面我把函数写成了被调用的格式,输入参数为多面体的顶点坐标。

代码 vpolyhedron.mfunction volume = vpolyhedron(vertex)

% calculate the volume of a polyhedron defined by the vertexes.

% Input:

%vertex: vertex of the polyhedron.

% Output:

%volume: volume of the polyhedron.

% Poweed by Xianbao Duan

% Email: xianbao.d@gmail.com

% Website: http://www.52souji.net/

% generate the Delaunay Triangle

dt = DelaunayTri(vertex);

% calculate the volumn of the body

[~, volume] = convexHull(dt);

下面举个例子具体讲解如何调用。

首先准备好多面体的顶点坐标文件 configure.in48.2134 49.1482 48.9853

48.2134 49.1482 51.8421

48.0908 51.1528 50.4137

52.4593 49.7390 48.9853

50.3190 47.7426 48.9853

50.3926 49.8086 47.5569

52.4594 49.7390 51.8421

50.3927 49.8087 53.2706

50.3190 47.7426 51.8421

52.3392 47.7448 50.4137

50.6354 51.8668 48.9853

50.6354 51.8668 51.8421

52.7074 51.7431 50.4137

50.0000 50.0000 50.4000

然后,可以使用如下代码调用。% load the vertexes of the polyhedron

p_coord = load('configure.in');

% calculate the volume

V = vpolyhedron(p_coord);

% display the result

disp(['The volume is: ',num2str(V)]);

程序的健壮性我不能保证,但我想一般的凸包多面体应该都可以吧。

如果有什么疑问或建议,给我留言。

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值