Sir I Want to place some target point in a reign of 100x100 and then cover them with Some sensor node like this given diagram, How I can do this?
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650480/image.png)
7 个评论
Walter Roberson
2021-6-29
Here is an example of re-arranging and cleaning up your code a bit, and using the positions of the targets to try to figure out good positions for nodes.
In this case I use the kmeans() algorithm to try to find placements.
This is a good example because we can see that the placement was unsuccessful, but we can also see that circles could have been placed to cover all of the targets. As you increase the number of nodes relative to the number of targets you increase the probability that it will not be possible to place the nodes to cover all of the targets. When you compare NN * pi*Trange^2 to prod(area) you can see that once you have filled more than that fraction with targets then you might not be able to cover all of them.
So, using kmeans() by itself is not the solution, but this arrangement of code will give you a better framework on how to construct a solution.
NN = 4; %number of nodes
NT = 10; %number of targets
Trange = 1;
area = [5,5];
% -----------------------------------------------------
% plot the targets
% -----------------------------------------------------
coords = area.*rand(NT,2);
plot(coords(:,1),coords(:,2),'*','color','r');
hold on
axis on equal
xlabel('x(m)')
ylabel('y(m)')
title('Initial Placement of Nodes with circular transmission range')
%place the nodes AFTER you have the target
nodes.pos=area(1).*rand(NT,2);
[~, nodes.pos] = kmeans(coords, NT, 'start', 'uniform')
%% plot the nodes deployment
% -----------------------------------------------------
plot(nodes.pos(:,1),nodes.pos(:,2),'.','color','b');
for ii=1:NN % plot the circular transmission range
[nodes.circle.x(ii,:),nodes.circle.y(ii,:)] = circle(nodes.pos(ii,1),nodes.pos(ii,2),Trange);
F6 = fill(nodes.circle.x(ii,:),nodes.circle.y(ii,:),[0.25,0.25,0.25]);
alpha 0.1
end
% -----------------------------------------------------
function [xunit,yunit] = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
% h = plot(xunit, yunit);
% hold off
end
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!