MATLAB-alphaShape二维使用

clc;clear all;
th = (pi/12:pi/12:2*pi)';
x1 = [reshape(cos(th)*(1:5), numel(cos(th)*(1:5)),1); 0];%numel数组元素的数目
y1 = [reshape(sin(th)*(1:5), numel(sin(th)*(1:5)),1); 0];%0的意义是显示圆心
x = [x1; x1+15];y = [y1; y1];
figure(1)
plot(x,y,'.')
axis equal
figure(2)
subplot(1,2,1)
plot(th,cos(th),'.')
subplot(1,2,2)
plot(th,sin(th),'.')
figure(3)
subplot(1,2,1)
plot(th,cos(th)*(1:5),'.')
subplot(1,2,2)
plot(th,sin(th)*(1:5),'.')
figure(4)
subplot(1,2,1)
plot(cos(th),sin(th),'.')
subplot(1,2,2)
plot(cos(th)*(1:5),sin(th)*(1:5),'.')
figure(5)
subplot(1,2,1)
plot( reshape(cos(th)*(1:5), numel(cos(th)*(1:5)),1),'.')
subplot(1,2,2)
plot( reshape(sin(th)*(1:5), numel(sin(th)*(1:5)),1),'.')
figure(6)
subplot(1,2,1)
x2=reshape(cos(th)*(1:5), numel(cos(th)*(1:5)),1);
y2=reshape(sin(th)*(1:5), numel(sin(th)*(1:5)),1);
t=length(x2);
plot(0:t,x1,'.')
subplot(1,2,2)
plot(0:t,y1,'.')
figure(7)
subplot(1,2,1)
plot(x,y,'.')
subplot(1,2,2)
plot( reshape(sin(th)*(1:5), numel(sin(th)*(1:5)),1),'.')
xx = [x2; x2+15];yy = [y2; y2];
plot(xx,yy,'.')
figure(8)
subplot(1,2,1)
shp1 = alphaShape(x,y);
shp1.Alpha%ans = 0.7752
plot(shp1)
subplot(1,2,2)
% 默认 alpha 半径可生成带不规则边界的 alpha 形状。要更好地捕获点集边界,请尝试更大的 alpha 半径。
% 使用 alpha 值 2.5 计算 alpha 形状。
shp1.Alpha = 2.5;
plot(shp1)
figure(9)
subplot(1,2,1)
shp2 = alphaShape(xx,yy);
plot(shp2) 
shp2.Alpha%ans = 0.7752
subplot(1,2,2)
% 默认 alpha 半径可生成带不规则边界的 alpha 形状。要更好地捕获点集边界,请尝试更大的 alpha 半径。
% 使用 alpha 值 2.5 计算 alpha 形状。
shp2.Alpha = 2.5;
plot(shp2)
figure(10)
x3 = [reshape(cos(th)*(2:5), numel(cos(th)*(2:5)),1); 0];%numel数组元素的数目
y3 = [reshape(sin(th)*(2:5), numel(sin(th)*(2:5)),1); 0];%0的意义是显示圆心
xxx = [x3; x3+15;];
yyy = [y3; y3];
plot(xxx,yyy,'.')
axis equal
figure(11)
shp3 = alphaShape(xxx,yyy,1);
plot(shp3)
figure(12)
% alpha 半径为 1 可生成带有两个包含孔的区域的 alpha 形状。
% 要隐藏 alpha 形状中的小孔,可以通过估计要填充的最大孔的面积来指定 HoleThreshold。
% 要填充形状中的所有孔,可以向 HoleThreshold 分配任意大的值。
% 通过指定 HoleThreshold 为 15 来新建一个隐藏这些孔的 alpha 形状。
shp4 = alphaShape(xxx,yyy,1,'HoleThreshold',15);
plot(shp4)
figure(13)
% 使用 alpha 半径 1 计算点集的 alpha 形状。生成的 alpha 形状有两个区域。
shp5 = alphaShape(x,y,1);
plot(shp5)
hold on
% 现在,通过直接向 shp.Points 矩阵添加新点来向 alpha 形状中添加第三个区域。
x4 = x1+8;
y4 = y1+10;
shp6 = alphaShape(x4,y4,1,'HoleThreshold',15);
plot(shp6)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值