How can I divide area into 12 sectors and deploy its nodes_locations ?

Hi,
Below is the Matlab-code to equally divided Area into 8 parts as in the picture below
% %Inputs: nodes_location: the coordinates of the nodes.
% Tx: Transmission powers of the nodes.
% threshold: the chosen threshold for clustering.
%Outputs: CH_I: Index of cluster heads.
% CH_T: Transmission powers of cluster heads.
% CM_T: Transmission powers of cluster members.
% CM_I: Index of cluster members.
% clusters: Indicates the size of each cluster.
function [CH_I , CH_T , CM_T , CM_I , clusters] = clustering(nodes_location , Tx , threshold)%H i add ce and cnn
global cluster_size
index = find(Tx > threshold);
cn = nodes_location(index , :);
clusters = zeros(8 , 50);
CH_I = [];
CH_T = [];
CM_L = [];
CM_T = [];
%Sector 1
index_s1 = find(cn(: , 1) >= 0 & cn(: , 1) <= cn(: , 2) & cn(: , 2) >= 0);
a_index_s1 = index(index_s1);
sector1 = cn(index_s1 , :);
Tx_sector1 = Tx(a_index_s1);
%Sector 2
index_s2 = find(cn(: , 1) >= 0 & cn(: , 1) > cn(: , 2) & cn(: , 2) >= 0);
a_index_s2 = index(index_s2);
sector2 = cn(index_s2 , :);
Tx_sector2 = Tx(a_index_s2);
%Sector 8
index_s8 = find(cn(: , 1) < 0 & abs(cn(: , 1)) <= cn(: , 2) & cn(: , 2) >= 0);
a_index_s8 = index(index_s8);
sector8 = cn(index_s8 , :);
Tx_sector8 = Tx(a_index_s8);
%Sector 7
index_s7 = find(cn(: , 1) < 0 & abs(cn(: , 1)) > cn(: , 2) & cn(: , 2) >= 0);
a_index_s7 = index(index_s7);
sector7 = cn(index_s7 , :);
Tx_sector7 = Tx(a_index_s7);
%Sector 3
index_s3 = find(cn(: , 1) >= 0 & cn(: , 1) > abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s3 = index(index_s3);
sector3 = cn(index_s3 , :);
Tx_sector3 = Tx(a_index_s3);
%Sector 4
index_s4 = find(cn(: , 1) >= 0 & cn(: , 1) <= abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s4 = index(index_s4);
sector4 = cn(index_s4 , :);
Tx_sector4 = Tx(a_index_s4);
%Sector 5
index_s5 = find(cn(: , 1) < 0 & abs(cn(: , 1)) <= abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s5 = index(index_s5);
sector5 = cn(index_s5 , :);
Tx_sector5 = Tx(a_index_s5);
%Sector 6
index_s6 = find(cn(: , 1) < 0 & abs(cn(: , 1)) > abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s6 = index(index_s6);
sector6 = cn(index_s6 , :);
Tx_sector6 = Tx(a_index_s6);
How the area can be split and deploy nodes into more parts, for instance (12) like pic below
%

2 commentaires

did you get the answer to this?
yes I posted code below https://www.mathworks.com/matlabcentral/answers/393205-how-can-i-divide-area-into-12-sectors-and-deploy-its-nodes_locations#comment_554235

Connectez-vous pour commenter.

Réponses (2)

I would suggest converting into polar form relative to the center of the circle, and then dividing according to groups of 2*pi/12 radians.

1 commentaire

if I have this code... How can I split it into 12 parts
clear all
close all
Nmax=1000;
r=1;
R=5;
for n=1:Nmax
%wrong method
r1(n)=r+R*rand(1,1);
theta1(n)=2*pi*rand(1,1);
% right method
% pdf_r(r)=(2/R^2) * r
% cumulative pdf_r is F_r = (2/R^2)* (r^2)/2
% inverse cumulative pdf is r = R*sqrt(F_r)
% so we generate the correct r as
r2(n) = r+R*sqrt(rand(1,1));
% and theta as before:
theta2(n)=2*pi*rand(1,1)./h;
% convert to cartesian
x1(n)=r1(n)*cos(theta1(n));
y1(n)=r1(n)*sin(theta1(n));
x2(n)=r2(n)*cos(theta2(n));
y2(n)=r2(n)*sin(theta2(n));
end
subplot(1,2,1)
plot(x1,y1,'r.')
axis([-1.1*R 1.1*R -1.1*R 1.1*R])
axis square
title('Wrong')
subplot(1,2,2)
plot(x2,y2,'g.')
axis([-1.1*R 1.1*R -1.1*R 1.1*R])
axis square
title('Right')
Thanks

Connectez-vous pour commenter.

Thank you Mr.Walter Roberson Could you explain how can divide it into 2*pi/12 ? (MATLAB CODE or any source if it is possible )
Regards,

1 commentaire

[th, r] = cart2pol( x - xc, y - yc );
sector_number = mod(floor(th / (2*pi/12) ) - 1, 12) + 1;

Connectez-vous pour commenter.

Catégories

En savoir plus sur WSNs dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by