2016-07-04 133 views
1

我在MATLAB繪製一個Delaunay圖像這樣的: - one角度計算的Delaunay圖

我要計算在圖中的所有角度。我有無序形式的所有點的x和y值,並且我不知道如何對點進行排序,因爲x和y值對於同一行上的這些點是接近的。

+0

http://se.mathworks.com/matlabcentral/answers/152631-to-calculate-the-angles-of-the-delaunay-triangles – KiW

回答

1

的一種方式做到這一點:

x = randn(1,4)*10; 
y = randn(1,4)*10; 

%calculate the triangulation 
tri = delaunay(x,y); 

%Plot the graph 
triplot(tri,x,y) 
hold on 

plot(x,y,'ro') 
text(x,y,strsplit(num2str(1:length(x)))) 


% Determine each angle 
for i = 1:size(tri,1) 
    per = perms(tri(i,:)); 
    [~, ind] = unique(per(:,2)); %avoid to calculate two time the same angle. 
    per = per(ind,:); %the 3 * 3 points that create the angle of each triangle 
    for j = 1:3 
     P_1 = per(j,1); 
     P1 = [x(P_1),y(P_1)]; 
     P_2 = per(j,2); 
     P2 = [x(P_2),y(P_2)]; 
     P_3 = per(j,3); 
     P3 = [x(P_3),y(P_3)]; 
     ANG = rad2deg(atan2(abs(det([P3-P2;P1-P2])),dot(P3-P2,P1-P2))); %P2 is the point in the middle 
     fprintf('Node %d %d %d angle %f\n',P_1, P_2, P_3, ANG) 
    end 
end 
+0

我喜歡你的答案,但是你的代碼存在錯誤。你需要改變你的循環條件'for i = 1:length(x)'可能是這樣的:'for i = 1:3'或者這個:'for i = 1:length(x)-1'或者this this :'for i = 1:size(tri,1)' –

+0

何耶當然是'1:size(tri,1)'謝謝 – obchardon