【问题标题】:Calculating Angles between connected line segments using MATLAB使用 MATLAB 计算连接线段之间的角度
【发布时间】:2014-10-11 15:38:32
【问题描述】:

我是第一次使用 MATLAB,编程经验很少。

我将三个坐标点与线段连接在一起,以创建一种锯齿形路径。如果从原点到第一个点的线段延伸超过第一个点,我需要找到从第一个点延伸的线到从第一个点延伸到第二个点的线的角度度量。对于第二点到第三点也需要这样做。我已经阅读了类似问题的解决方案,但我无法根据我的情况解释和修改它们。

【问题讨论】:

标签: matlab line points segments angle


【解决方案1】:

假设你的坐标是:

coord = [1 2; 2 4; 1.5 1; 4 2]
coord =
    1.0000    2.0000
    2.0000    4.0000
    1.5000    1.0000
    4.0000    2.0000

这将给出以下之字形图案:

要查找每个线段的角度,您可以执行以下操作:

coord_diff = diff(coord) %// Find the difference between each 
                         %// coordinate (i.e. the line between the points)

%// Make use of complex numbers. A vector is 
%// given by x + i*y, where i is the imaginary unit
vector = coord_diff(:,1) + 1i * coord_diff(:,2);

line_angles = angle(vector) * 180/pi; %// Line angles given in degrees  
diff_line_angle = diff(line_angles)   %// The difference in angle between each line segment

这给出了以下角度,在检查图表时似乎是合理的。

line_angles =    
   63.4349
  -99.4623
   21.8014

diff_line_angle =
 -162.8973
  121.2637

cmets 后更新

coord = [0 0; 3 4; -1 7; 3 10]   
coord =
     0     0
     3     4
    -1     7
     3    10

coord_diff = diff(coord) %// Find the difference between each 
                         %// coordinate (i.e. the line between the points)
coord_diff =
     3     4
    -4     3
     4     3
%// The angles of these lines are approximately 36.86 and 53.13 degrees

%// Make use of complex numbers. A vector is 
%// given by x + i*y, where i is the imaginary unit
vector = coord_diff(:,1) + 1i * coord_diff(:,2);

line_angles = angle(vector) * 180/pi; %// Line angles given in degrees
line_angles =
   53.1301
  143.1301
   36.8699    

我不确定你想如何对待不同的迹象等,但这样的事情应该可以工作:

[90-line_angles(1), arrayfun(@(n) line_angles(n+1)-line_angles(n), ...
    1:numel(line_angles)-1)].'
ans =
   36.8699
   90.0000
 -106.2602

这更简单,但如果您需要更改标志或类似的东西,则更难适应:

[90-line_angles(1); diff(line_angles)]

【讨论】:

  • 感谢您的回复,但我认为这不是我想要的。应该归咎于我的模糊问题。这里还有一些细节。第一段必须从原点开始,并且每个连续点的 Y 值必须大于最后一段,从而形成垂直之字形。然后通过将每条线段延伸超过之字形弯曲的点并测量从突出线段到下一个坐标的角度。如果我有十个声望并且可以发布图像,我相信它会变得清晰。
  • 在 pastebin、imgur 或类似的东西上发布图片链接,然后有人可以为您上传。但现在有了新信息,情况就更清楚了。我相信我的回答只是与您想要的不同而已。如果矩阵的第一行是[0 0],您可以通过line_angles(n)-line_angles(n-1) 找到您要查找的内容。我稍后会更新我的答案:-)
  • 这里是图片的链接。蓝色弧线是我需要的角度测量值。 imgur.com/wz15nAh感谢您的帮助!
  • 我无意打扰您,但我似乎仍然无法获得代码来解决手动解决问题时得到的解决方案。如果您可以查看我发布的图片的链接并给我更多的指导,我将不胜感激!感谢您的帮助!
  • @user1,我不确定你想如何对待不同的迹象,但我认为更新会对你有所帮助。 =)
猜你喜欢
  • 1970-01-01
  • 2019-07-09
  • 2017-03-20
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
  • 2014-06-21
  • 1970-01-01
相关资源
最近更新 更多