复共线性 matlab,识别所有共线线段(在matlab中)

此代码查找线的共线组.

theta = zeros(length(lines),1);

rho = zeros(length(lines),1);

for k = 1:length(lines)

xy = [lines(k).point1; lines(k).point2];

plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');

plot(xy(1,1),xy(1,2),'x','LineWidth',1,'Color','yellow');

plot(xy(2,1),xy(2,2),'x','LineWidth',1,'Color','red');

%text(xy(1,1),xy(1,2),[' ' num2str(k)],'fontsize',10,'color',[1 1 1]);

theta(k) = lines(k).theta;

rho(k) = lines(k).rho;

end

theta_tolerance = 2;

theta2 = abs(bsxfun(@minus, theta, theta')) <= theta_tolerance;

theta2(1:size(theta2,2)+1:numel(theta2)) = 0; % zero diagonal

rho_tolerance = 1;

rho2 = abs(bsxfun(@minus, rho, rho')) <= rho_tolerance;

rho2(1:size(rho2,2)+1:numel(rho2)) = 0; % zero diagonal

rhotheta2 = sparse(rho2 & theta2);

[nc, C] = graphconncomp(rhotheta2);

paired = ismember(C,find(hist(C,1:max(C))>1)); % paired lines

colors=get(gcf,'DefaultAxesColorOrder');

for line=find(paired)

xy = [lines(line).point1; lines(line).point2];

plot(xy(:,1),xy(:,2),':','LineWidth',4,'Color',colors(C(line),:));

text(xy(1,1),xy(1,2),num2str(C(line)),'fontsize',20,'Color',colors(C(line),:));

end

它没有照顾重叠.目前尚不清楚如何处理具有3个共线段的情况,其中第一段和第二段相交?您是否需要同时考虑包含第一个和第三个的集以及包含第二个和第三个段的集合?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值