【问题标题】:Angle calculation in a Delaunay graphDelaunay 图中的角度计算
【发布时间】:2016-11-06 06:44:46
【问题描述】:

我在 MATLAB 中绘制了一个像这样的 Delaunay 图:-

我想计算图中的所有角度。我有无序形式的所有点的 x 和 y 值,我不知道如何对这些点进行排序,因为 x 和 y 值对于同一行上的那些点很接近。

【问题讨论】:

标签: matlab matlab-figure delaunay


【解决方案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

【讨论】:

  • 我喜欢你的回答,但你的代码有错误。您需要将循环条件 for i = 1:length(x) 更改为:for i = 1:3 或此:for i = 1:length(x)-1 或此:for i = 1:size(tri,1)
猜你喜欢
  • 2014-04-02
  • 2020-05-09
  • 1970-01-01
  • 2012-05-25
  • 1970-01-01
  • 2017-09-01
  • 2019-01-06
  • 1970-01-01
  • 2014-05-29
相关资源
最近更新 更多