2011-07-12 27 views
0

我已經創建了一個代碼,它接受來自用戶輸入的鄰接矩陣並創建矩陣的三維散點圖。我想在未連接的節點之間分配一個斥力,並在連接的節點之間引入一個吸引力,這樣節點就會根據作用在其上的淨力而移動。這必須是3d。如何使用力導向算法從鄰接矩陣生成3d圖

+1

...什麼有_you_嘗試? – abcd

回答

1

這裏是表示,鑑於鄰接矩陣和頂點的座標,我們繪製圖的三維散點的例子:

%# sample adjacency matrix and 3D coordinates of points 
N = 30;          %# number of vertices 
[adj,XYZ] = bucky; 
adj = full(adj); adj = adj(1:N,1:N); 
x = XYZ(1:N,1); y = XYZ(1:N,2); z = XYZ(1:N,3); 
labels = cellstr(num2str((1:N)','%02d')); %'# nodes labels 

%# another sample data 
%#x = rand(N,1);   %# x-coords of vertices 
%#y = rand(N,1);   %# y-coords 
%#z = rand(N,1);   %# z-coords 
%#adj = rand(N,N)>0.7; %# adjacency matrix 

%# plot graph in 3D 
[r c] = find(adj); 
p = [r c]';    %'# indices 
plot3(x(p), y(p), z(p), 'LineWidth',2, 'Color',[.4 .4 1], ... 
    'Marker','o', 'MarkerSize',10, ... 
    'MarkerFaceColor','g', 'MarkerEdgeColor','g') 
text(x, y, z, labels, ... 
    'EdgeColor','g', 'BackgroundColor',[.7 1 .7], ... 
    'VerticalAlignment','bottom', 'HorizontalAlignment','left') 
axis vis3d, box on, view(3) 
xlabel('x'), ylabel('y'), zlabel('z') 

screenshot

恐怕另一部分是更多的參與,你將不得不表明,你付出了一些努力之前,有人會試圖幫助你...