function x_est = CAB(A, r, R)
B = A(:, r~=0);%filter the pseudo-circles with radius of 0
r1 = r(r~=0);
center = [B A];
radius = [r1; R];
n = length(radius);
tolerance = 1e-5; % this parameter is used to cancel the impact of numerical accuracy.
intersect_point = [];
for i = 1:n-1
for j = i+1:n
a1 = center(:,i);
a2 = center(:,j);
if norm(a1-a2)==0
continue;
end
r1 = radius(i);
r2 = radius(j);
pp = intersect(a1, a2, r1, r2);
intersect_point = [intersect_point pp];
end
end
if length(intersect_point)==0
error('all circles do not intersect each other', '%s', 'exceptional case');
end
m = length(r);
n = size(intersect_point, 2);
degree = zeros(n, 1);
for i=1:n
pp = intersect_point(:,i);
for j=1:m
dist = norm(pp-A(:,j));
if dist<=R(j)+tolerance & dist>=r(j)-tolerance
degree(i) = degree(i)+1;
end
end
end
%degree
valid_intersect_point = [];
if max(degree)==m %the feasible case
valid_intersect_point = intersect_point(:, degree==m);
x_est = mean(valid_intersect_point, 2);
else
%TPDS method in random walk case
%%select k points with highest degree in the infeasible case
%[deg, index] = sort(degree, 'descend');
%k = 3;%assume k=3, that is, the first three points are selected to estimate the position of unknown node, but you can vary k to obtain different estimation performance
%x_est = mean(intersect_point(:, index(1:k)), 2);
%variant of TPDS method
%select all points with highest degree in the feasible case
valid_intersect_point = intersect_point(:, degree==max(degree));
x_est = mean(valid_intersect_point, 2);
end
return
function pp = intersect(a1, a2, r1, r2)
x1 = a1(1); y1 = a1(2);
x2 = a2(1); y2 = a2(2);
t = (x1^2+y1^2)-(x2^2+y2^2)-r1^2+r2^2;
bx = 2*(x1-x2); by = 2*(y1-y2);
d = r1^2-x1^2-y1^2;
if bx==0%the exceptional case
y = t/by;
a = 1;
b = -2*x1;
c = -d+y^2-2*y*y1;
temp = b^2-4*a*c;
if temp==0
x = -b/(2*a);
pp = [x; y];
elseif temp>0
x = (-b+sqrt(temp))/(2*a);
p1 = [x; y];
x = (-b-sqrt(temp))/(2*a);
p2 = [x; y];
pp = [p1 p2];
else
pp = [];
end
return;
end
a = (by/bx)^2+1;
b = -2*by*t/bx^2+2*x1*by/bx-2*y1;
c = (t/bx)^2-2*x1*t/bx-d;
temp = b^2-4*a*c;
if temp==0%only one intersection point
y = -b/(2*a);
x = (t-by*y)/bx;
pp = [x; y];
elseif temp>0%two intersection points
y = (-b+sqrt(temp))/(2*a);
x = (t-by*y)/bx;
p1 = [x; y];
y = (-b-sqrt(temp))/(2*a);
x = (t-by*y)/bx;
p2 = [x; y];
pp = [p1 p2];
else
pp = [];
%error('exception', '%s', 'there exists exception');
end
return;
IT狂飙
- 粉丝: 4841
- 资源: 2650
最新资源
- 基于HarmonyOS的鸿蒙网络编程设计源码
- 基于小程序的“最多跑一次”源码(小程序毕业设计完整源码+LW).zip
- 仓储系统服务端 基于偌依的单体架构springboot
- 基于小程序的个人健康信息管理小程序源码(小程序毕业设计完整源码).zip
- 基于LLM模型驱动的在线网页PPT制作工具设计源码
- 基于Vue框架的日期选择器组件CSS设计源码
- 基于小程序的使命召唤游戏助手的设计与实现源码(小程序毕业设计完整源码+LW).zip
- 基于Java、Vue等技术的模拟社区核酸检测管理系统设计源码
- CM311-5 HV 固件包
- 基于群晖Synology Audio Station的AsMusic第三方音乐播放器设计源码
- 基于pythonQt5实现的跑马灯效果,作为pythonQt 5的入门例子很适合,已经将每一行代码标注了解释,很好的入门案例
- 基于小程序的党员之家服务系统小程序源码(小程序毕业设计完整源码+LW).zip
- 基于Vue框架的母婴商城小程序设计源码
- 基于Spring Boot、Mybatis-plus、MySQL的React硅谷后台项目后端代码设计源码
- 基于小程序的党建工作小秘书源码(小程序毕业设计完整源码).zip
- 基于110法律咨询网数据的医疗纠纷小程序设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈