我有个问题。我有一组 x 和 y 坐标,我可以通过它绘制轮廓或闭合图形。然而,在我在程序中的操作过程中,坐标的顺序可能会改变。因此,现在如果绘制了绘图,则曲线未正确绘制。
下面在我的代码中给出了一个说明:
clc;
clear all
close all
xi = [86.7342,186.4808,237.0912,194.8340,84.2774,39.5633,86.7342];
yi = [18.2518,18.2518,102.3394,176.4611,172.1010,88.6363,18.2518];
subplot(1,2,1),plot(xi,yi);
title('original points contour');
xii=xi; yii=yi;
%Suppose the points are interchanged
t=0;
t=xii(3); xii(3)=xii(4); xii(4)=t;
t=yii(3); yii(3)=yii(4); yii(4)=t;
subplot(1,2,2),plot(xii,yii);
title('Redrawn contour with the points exchanged');
%I get this contour.
这两个图显示在代码中。
无论元素的顺序如何,我都需要能够重新绘制正确的轮廓。我应该使用排序算法吗?如何确定点的顺序以形成没有任何交点的良好闭合轮廓?提前致谢。
注意::假设在操作过程中我的坐标集变成了这样:
xiiii =[40,200,210,230,50,20,40]
yiiii =[50,60,160,80,120,30,50]
figure();
plot(xiiii,yiiii,'+r'); hold on;
% I need to somehow change the matrices in such a way so as to form
%an non-overlapping closed surface.
%after manipulation I get should get this matrices
xiii =[40,200,230,210,50,20,40];
yiii =[50,60,80,160,120,30,50];
plot(xiii,yiii,'+b');
hold off;
%Notice the difference between the two plots. I require the 2nd plot.
我希望这个例子能说明我的问题。再次感谢大家。