-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInitialPosition.m
More file actions
53 lines (39 loc) · 1.5 KB
/
InitialPosition.m
File metadata and controls
53 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function out_node_struct = InitialPosition(in_node_struct,init_size)
%INITIALPOSITION initiallizes the positions of the nodes in the 2D disk.
% input:
% N: number of nodes.
% degree_vector: degree of the nodes in a ROW vector.
% init_size: size of the initial disk.
% output:
% position_mat: the position matrix in Euclidean form (size = 2xN).
% purpose:
% distribute the nodes according to the degree, the smaller the degree, the
% closer to the edge of the disk.
% 2011-5-26 21:25:24
% Kechao
% Revised: 2011-5-30 9:54:10
% Kechao
% Verification of the input.
% if length(hop_mat) ~= length(in_node_struct)
% error('myApp:argChk','Wrong input,how many number of nodes?')
% end
out_node_struct = in_node_struct;
% Generate the degree vector.(Horizontal cat)
degree_vector = [in_node_struct.degree];
% Assign the Polar coordinates.
rand_radius = 1./(degree_vector+1) * init_size;
rand_theta = 2*pi*rand(1,N);
for node_i = 1:length(in_node_struct)
for node_j = in_node_struct(node_i).neighbors_1hop
if degree_vector(node_i) < degree_vector(node_j)...
&& degree_vector(node_i) <= 2
rand_theta(node_i) = rand_theta(node_j) + 4*rand(1)*pi/180;
% Transform Polar to Euclidean.
x = rand_radius(node_i).*cos(rand_theta(node_i));
y = rand_radius(node_i).*sin(rand_theta(node_i));
% Output the Euclidean coordinates.
out_node_struct(node_i).position = [x;y];
end
end
end
return