% 画传感器所在的位置 angles = (1/n:1/n:1)*2*pi; xdata = r.*cos(angles); ydata = r.*sin(angles); plot(xdata,ydata,"b*"); hold on
% 生成随机一点 theta = rand*(2*pi); r0 = rand*r; x = r0.*cos(theta); y = r0.*sin(theta); plot(x,y,"bo"); hold on
% 计算测量到的距离 d = zeros(n,1); d1 = zeros(n,1); fori=1:n err_x = -err_install + 2*err_install*rand(1); % +-安装误差 err_y = -err_install + 2*err_install*rand(1); a = [xdata(i)+err_x ydata(i)+err_y]; b = [x y]; d(i) = fix(norm(a-b)+err*rand); d1(i) = d(i)-d(1); end
% 方法一泰勒展开取一次项,降维转线性,计算参数l和m d0 = zeros(n,1); l = zeros(n,1); m = zeros(n,1); fori=1:n a = [xdata(i) ydata(i)]; d0(i) = r; l(i) = xdata(i)/d0(i); m(i) = ydata(i)/d0(i); end A = [l m]; L = d0-d; X = (A'*A)\(A'*L); plot(X(1),X(2),"g*");
% 方法二 % 计算到基站一的距离 x1 = zeros(n,1); y1 = zeros(n,1); c = zeros(n,1); K = zeros(n,1); fori=1:n K(i) = xdata(i)^2+ydata(i)^2; x1(i) = xdata(i)-xdata(1); y1(i) = ydata(i)-ydata(1); c(i) = (K(i)-K(1))-(d1(i)^2+2*d1(i)*d(1)); c(i) = c(i)/2; end A = [x1 y1]; A = A(2:end,:); L = c(2:end); X = (A'*A)\(A'*L); plot(X(1),X(2),"r*");
% 检测fov25°传感器个数 c = zeros(1,n); e = zeros(1,n); fori=1:n a = [xdata(i) ydata(i)]; b = [xdata(i)-x ydata(i)-y]; c(i) = acos(dot(a,b)/norm(a)/norm(b)); end point = 10-floor(norm([x y])/15); num = sum((c<(12.5/180*pi))&(d'>40)); % 加上盲区判断,最大盲区值为40mm s = sprintf("识别到的传感器个数:%d,环数:%d",num,point); disp(s);
% 检测fov25°传感器个数 c = zeros(1,n); e = zeros(1,n); fori=1:n a = [xdata(i) ydata(i)]; b = [xdata(i)-x ydata(i)-y]; c(i) = acos(dot(a,b)/norm(a)/norm(b)); end point = 10-floor(norm([x y])/15); num = sum((c<(12.5/180*pi))&(d'>40)); % 加上盲区判断,最大盲区值为40mm s = sprintf("识别到的传感器个数:%d,环数:%d",num,point); disp(s);