假设你的坐标是:
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)]