【问题标题】:Getting the points of a certain plot in matlab在matlab中获取某个图的点
【发布时间】:2013-05-22 22:35:14
【问题描述】:

如果我在 matlab 的图中有随机排序的点,并且在绘制时会产生各种闭合形状。给定一个封闭形状左侧的特定点,我如何才能以矢量形式获取该形状的所有点,记住收集点的惯例是顺时针方向移动。

【问题讨论】:

标签: matlab


【解决方案1】:

注释示例:

cla
% Random data
x = rand(15,1);
y = rand(15,1);
scatter(x,y)
% Random point to the left
hold on
p = [-0.1, rand(1)*0.2 + 0.5];
plot(p(1),p(2),'*r')

% Separate points that lie above your point
idx = y >= p(2);

% Sort x then y increasing for upper half and x then y decreasing for lower half 
shape = [sortrows([x( idx) y( idx)],[1 2]) 
         sortrows([x(~idx) y(~idx)],[-1 -2])];

通过绘制一条空线检查shape 是否包含顺时针排序的坐标:

% Plot clockwise open line
plot(shape(1:end ,1),shape(1:end,2),'k')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 2017-07-20
    相关资源
    最近更新 更多