我有一个问题。 我有一组x和y坐标,通过它我可以绘制轮廓或封闭的图形。但是,在我的程序中,坐标的顺序可能会改变。所以现在如果绘制了曲线,曲线并不是正确的。绘制轮廓分类matlab
一个实例是下面给出在我的代码:
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.
我希望这个例子让清楚我的问题。 再次感谢所有。
您是否尝试在第一阶段保存索引向量? – NKN
不,我没有。但即使我这样做也不能解决我的问题。为了更清楚地说明我正在编辑这个问题。也许那时它会变得更加清晰。 – roni
请看我编辑的问题。 – roni