如何根据非连续数据点绘制带间隙的边界线?

How to plot a boundary line with a gap based on non-consecutive data points?

请检查下面解释问题的代码:

scatter(wall_agents(:,2),wall_agents(:,3),.095*ones*size(wall_agents,1),'filled','MarkerFaceColor',LineSpec,'black');

    x=wall_agents(:,2);
    y=wall_agents(:,3)
    k = boundary(x,y);
    hold on;
    plot(x(k),y(k));

如何绘制散点图中所示的带间隙的边界?

数据: 这里,第二列是 x,第三列是 y。

 wall_agents =



   10.0000    2.5714    1.2857
   14.0000   -2.5714   -0.2857
  211.0000   -2.5714   -2.5000
  195.0000    2.5714    2.0714
  144.0000    1.2857    2.4286
   51.0000    2.5714   -0.4286
  104.0000    1.4286   -2.5714
   59.0000   -2.5714   -2.2857
  305.0000   -2.5000    2.4286
  116.0000   -0.5714    2.4286
   16.0000   -2.5714    0.1429
  239.0000   -0.6429    2.4286
  261.0000   -0.7857   -2.5714
  260.0000    1.9286    2.4286
  138.0000    2.0000    2.4286
   49.0000    2.5714    0.1429
  120.0000   -1.7143    2.4286
   62.0000   -2.5714   -1.8571
   58.0000   -2.5714   -2.0000
   36.0000    2.5714    2.4286
   78.0000   -2.5714    2.1429
  208.0000   -2.5714    0.9286
   12.0000    2.5714    1.4286
  126.0000   -1.0000   -2.5714
  109.0000    2.1429   -2.5714
  225.0000   -2.5714   -1.3571
  273.0000    0.7857   -2.5714
  230.0000   -2.5714   -1.2143
  286.0000    0.5000   -2.5714
  159.0000   -2.5714   -0.0714
  118.0000   -1.4286    2.4286
  169.0000    2.5714   -0.2143
   93.0000         0   -2.5714
   69.0000   -2.5714   -1.0000
  108.0000    1.8571   -2.5714
   98.0000    0.8571   -2.5714
  276.0000   -1.5000    2.4286
  131.0000   -0.5714   -2.5714
  277.0000   -2.0714    2.4286
   48.0000    2.5714   -1.5714
   56.0000   -2.5714   -1.5714
  297.0000    2.5000   -2.5714
  281.0000   -1.6429    2.4286
  252.0000    0.7857    2.4286
  279.0000   -2.2143    2.4286
  167.0000    2.5714   -0.9286
  105.0000    1.5714   -2.5714
  306.0000   -2.5000   -2.5714
   64.0000   -2.5714   -0.8571
  295.0000    1.7857   -2.5714
  210.0000   -2.5714   -2.0714
  268.0000    0.6429   -2.5714
  249.0000    1.0714    2.4286
  224.0000   -2.5714   -0.9286
  274.0000    1.5000   -2.5714
  207.0000   -2.5714    0.5000
   46.0000    2.5714   -2.1429
   65.0000   -2.5714   -1.1429
  218.0000    2.5714   -2.2143
  164.0000    2.5714   -0.6429
   57.0000   -2.5714   -1.7143
  213.0000   -2.5714   -1.9286
   42.0000    2.5714   -2.2857
  183.0000   -2.5714    1.9286
  143.0000    1.1429    2.4286
    7.0000    2.5714    1.1429
  222.0000    2.5714   -2.5000
   32.0000    2.5714   -1.1429
   88.0000   -1.5714   -2.5714
  290.0000    1.6429   -2.5714
  223.0000    2.5714   -2.3571
  205.0000   -2.5714    1.2143
  300.0000   -1.6429   -2.5714
   85.0000   -2.1429   -2.5714
  245.0000   -0.7857    2.4286
  110.0000    2.4286   -2.5714
  106.0000    2.2857   -2.5714
   89.0000   -2.0000   -2.5714
  157.0000   -2.5714    0.0714
  272.0000    0.9286   -2.5714
   31.0000    2.5714   -0.8571
  304.0000   -2.3571   -2.5714
   94.0000   -0.1429   -2.5714
  160.0000   -2.5714   -0.3571
  133.0000    2.4286    2.4286
  250.0000    1.5000    2.4286
  139.0000    1.7143    2.4286
  203.0000   -2.5714    1.0714
  294.0000    1.5714   -2.5714
  298.0000   -1.9286   -2.5714
  111.0000    2.0000   -2.5714
  184.0000   -2.5714    1.7857
  251.0000    0.6429    2.4286
  119.0000   -2.1429    2.4286
  221.0000    2.5714   -1.7857
   84.0000   -2.2857   -2.5714
  161.0000    2.5714   -1.3571
   38.0000    2.5714    2.0000
  258.0000    2.3571    2.4286
   33.0000    2.5714   -1.4286
  241.0000   -1.2143    2.4286
  142.0000    0.8571    2.4286
  123.0000   -1.5714    2.4286
  189.0000    2.5714    2.2143
   61.0000   -2.5714   -2.1429
  117.0000   -0.8571    2.4286
   30.0000    2.5714   -1.0000
  200.0000    2.5714    1.2143
   52.0000    2.5714    0.4286
  302.0000   -2.0714   -2.5714
  265.0000   -1.3571   -2.5714
  301.0000   -1.5000   -2.5714
   55.0000    2.5714   -0.1429
  171.0000    2.5714   -0.3571
   66.0000   -2.5714   -0.7143
  140.0000    0.7143    2.4286
  114.0000   -1.0000    2.4286
  243.0000   -0.9286    2.4286
   63.0000   -2.5714   -1.4286
  107.0000    1.7143   -2.5714
   53.0000    2.5714   -0.2857
  228.0000   -2.5714   -0.6429
  188.0000   -2.5714    1.5000
  206.0000   -2.5714    0.7857
  145.0000    1.4286    2.4286
  103.0000    1.2857   -2.5714
  182.0000   -2.5714    2.3571
  121.0000   -1.8571    2.4286
  185.0000   -2.5714    1.6429
  194.0000    2.5714    1.5000
  262.0000   -1.0714   -2.5714
   41.0000    2.5714    1.5714
   15.0000   -2.5714         0
   99.0000    1.0000   -2.5714
  215.0000   -2.5714   -2.3571
  204.0000   -2.5714    0.6429
  292.0000    2.3571   -2.5714
   24.0000   -2.5714    0.8571
   80.0000   -2.5714    1.5714
  174.0000    2.5714   -0.5000
   44.0000    2.5714   -2.4286
   25.0000   -2.5714    1.1429
  266.0000   -0.5000   -2.5714
   37.0000    2.5714    1.7143
  282.0000   -0.4286   -2.5714
  256.0000    1.7857    2.4286
  102.0000    1.1429   -2.5714
   18.0000   -2.5714   -0.4286
  254.0000    1.5714    2.4286
  187.0000   -2.5714    2.2143
  127.0000   -0.8571   -2.5714
   47.0000    2.5714   -1.8571
  219.0000    2.5714   -1.9286
  288.0000    0.3571   -2.5714
   72.0000   -2.5714   -2.5714
  226.0000   -2.5714   -1.0714
  275.0000   -2.3571    2.4286
  136.0000    2.1429    2.4286
  278.0000   -1.7857    2.4286
  100.0000    0.7143   -2.5714
  202.0000    2.5714    0.9286
  229.0000   -2.5714   -0.7857
  137.0000    2.2857    2.4286
  255.0000    2.2143    2.4286
   39.0000    2.5714    1.8571
  264.0000   -1.2143   -2.5714
  112.0000   -1.2857    2.4286
  244.0000   -1.0714    2.4286
  280.0000   -1.9286    2.4286
   86.0000   -1.8571   -2.5714
   50.0000    2.5714         0
  122.0000   -2.2857    2.4286
  135.0000    1.8571    2.4286
  113.0000   -0.7143    2.4286
  186.0000   -2.5714    2.0714
  259.0000    2.0714    2.4286
   19.0000   -2.5714    0.4286
  284.0000    0.0714   -2.5714
  158.0000   -2.5714    0.2143
  263.0000   -0.6429   -2.5714
  201.0000    2.5714    0.5000
   23.0000   -2.5714    1.0000
  270.0000    1.3571   -2.5714
   13.0000    2.5714    1.0000
  217.0000    2.5714   -2.0714
   92.0000    0.2857   -2.5714
   82.0000   -2.5714    1.7143
   27.0000   -2.5714    0.7143
  212.0000   -2.5714   -1.6429
  303.0000   -1.7857   -2.5714
    8.0000    2.5714    0.8571
  247.0000    0.9286    2.4286
  125.0000   -2.4286    2.4286
   96.0000    0.1429   -2.5714
   20.0000   -2.5714   -0.1429
  192.0000    2.5714    2.3571
   81.0000   -2.5714    1.8571
  227.0000   -2.5714   -1.5000
  209.0000   -2.5714    1.3571
   97.0000   -0.4286   -2.5714
   60.0000   -2.5714   -2.4286
  291.0000    1.9286   -2.5714
   79.0000   -2.5714    2.0000
  190.0000    2.5714    1.7857
  165.0000    2.5714   -0.7857
  172.0000    2.5714    0.0714
  287.0000    0.2143   -2.5714
  296.0000    2.0714   -2.5714
  154.0000   -2.5714    0.3571
  289.0000   -0.3571   -2.5714
   21.0000   -2.5714    1.2857
   67.0000   -2.5714   -1.2857
    9.0000    2.5714    0.5714
    2.0000    2.5714   -2.5714
  173.0000    2.5714    0.2143
   77.0000   -2.5714    2.2857
   28.0000    2.5714   -1.2857
  163.0000    2.5714   -1.5000
  166.0000    2.5714   -1.0714
  285.0000   -0.2143   -2.5714
  101.0000    0.5714   -2.5714
  283.0000   -0.0714   -2.5714
  129.0000   -1.2857   -2.5714
  146.0000    1.0000    2.4286
  197.0000    2.5714    1.0714
  248.0000    1.2143    2.4286
  299.0000   -2.2143   -2.5714
   22.0000   -2.5714    0.5714
  191.0000    2.5714    1.6429
   45.0000    2.5714   -1.7143
   26.0000   -2.5714    1.4286
  115.0000   -1.1429    2.4286
  267.0000   -0.9286   -2.5714
  216.0000   -2.5714   -2.2143
  293.0000    2.2143   -2.5714
  130.0000   -1.1429   -2.5714
  220.0000    2.5714   -1.6429
  170.0000    2.5714   -0.0714
   34.0000    2.5714   -0.7143
  246.0000    1.3571    2.4286
  196.0000    2.5714    0.7857
  199.0000    2.5714    1.3571
   35.0000    2.5714    2.1429
   11.0000    2.5714    0.7143
  242.0000   -1.3571    2.4286
   83.0000   -2.5714    2.4286
   17.0000   -2.5714    0.2857
  271.0000    1.0714   -2.5714
   43.0000    2.5714   -2.0000
   54.0000    2.5714    0.2857
   40.0000    2.5714    2.2857
   29.0000    2.5714   -0.5714
  214.0000   -2.5714   -1.7857
  124.0000   -2.0000    2.4286
  134.0000    1.5714    2.4286
  155.0000   -2.5714   -0.5000
  193.0000    2.5714    1.9286
  168.0000    2.5714    0.3571
   95.0000   -0.2857   -2.5714
   90.0000   -2.4286   -2.5714
  269.0000    1.2143   -2.5714
   68.0000   -2.5714   -0.5714
  156.0000   -2.5714   -0.2143
  128.0000   -0.7143   -2.5714
  132.0000   -1.4286   -2.5714
  257.0000    1.6429    2.4286
   91.0000    0.4286   -2.5714
  198.0000    2.5714    0.6429
  141.0000    0.5714    2.4286
  253.0000    2.5000    2.4286
  162.0000    2.5714   -1.2143
   87.0000   -1.7143   -2.5714

以下解决方案假设间隙的宽度总是比两个数据点之间的距离。我也假设它是一种凸形,我不能保证它适用于所有形状。

%// load data
DATA = load('data.txt');
x = DATA(:,2);
y = DATA(:,3);

%// find center of boundary
x_center = mean(x);
y_center = mean(y);

%// shift data to center
x_biased = x - x_center;
y_biased = y - y_center;

%// get angle
vec = x_biased + 1j*y_biased;
angvec = angle(vec);

%// sort data according to angle
[ang_sorted,idx] = sort(angvec);

x_sorted = x(idx);
y_sorted = y(idx);

%// find idx of angle of gap
[~,maxidx] = max(abs(diff(ang_sorted)));

%// shift sorted data by index of gap
x_shifted = circshift(x_sorted(:),-maxidx);
y_shifted = circshift(y_sorted(:),-maxidx);

%// plot result
scatter(x,y), hold on;
plot(x_shifted,y_shifted,'LineWidth',2)

相同的解决方案,有点局促:

%// load data
DATA = load('data.txt');
x = DATA(:,2);
y = DATA(:,3);

%// calcs
[ang_sorted,idx] = sort(angle((x - mean(x)) + 1j*(y - mean(y))));
[~,maxidx] = max(abs(diff(ang_sorted)));
plotdata = circshift(DATA(idx(:),:),-maxidx);

%// plot result
scatter(x,y), hold on;
plot(plotdata(:,2),plotdata(:,3),'LineWidth',2)