【问题标题】:finding intersection points in x y data for calculating area of the enclosed area在 x y 数据中查找交点以计算封闭区域的面积
【发布时间】:2020-02-07 13:00:14
【问题描述】:

我有 x 和 y 数据点,在绘制数据后,我有这个下图。数据是分散的 x y 数据,其中包含交叉点。我想在图上绘制这些交点,如下所示。我如何找到这些交叉点?我只能找到计算两条线的交点但不能像这样分散数据的函数。我的主要目的是分离每个盒子状结构并使用交叉点测量面积,因为这种方法将是自动化的。

【问题讨论】:

  • 如果您的工作流程手动查找交叉点有意义,那么您可以使用 input 覆盖散点图。在这种情况下,请将您的问题相应地更新为如何记录覆盖到散点图的手动输入的坐标。如果您以编程方式需要交叉点,我不知道标准算法可以做这样的事情,并且要求超出标准库/函数的建议在 SO 上是题外话。在这种情况下,您可能应该就如何实现您可能想到的特定插值方法提出更具体的问题。
  • 至于面积,获得由(每 4 个)点包围的(正方形)面积是一个不同的问题——在这个问题上,您还可以从提出更集中的问题中受益。

标签: matlab


【解决方案1】:

如果线条总是水平和垂直,那么你可以这样做

discriminationCritera = 5 ; % Will need to play with this, how many times more counts does an area need to have to be considered a line
[ N , Xedges , Yedges , binX , binY ] = histcounts2(x,y); % bins the data

% Find number of data points in each row and column
Xsum = sum(N,2);
Ysum = sum(N,1);

% Decided whether it is dense enough to be considered a line
XLines = find( Xsum > discriminationCritera * median(Xsum) );
YLines = find( Ysum > discriminationCritera * median(Ysum) );

% figure out which points are in that bin
xlines = sort(arrayfun(@(line) mean(x( line == binX ) ) , XLines ));
ylines = sort(arrayfun(@(line) mean(y( line == binY ) ) , yLines ));

% Display results
disp(strjoin( ...
[ arrayfun(@(x) sprintf( 'x = %g' , x ), xlines(:) , 'uni', 0)
  arrayfun(@(y) sprintf( 'y = %g' , y ), ylines(:) , 'uni', 0) ] ...
, '\n' ) )

% Calculate areas, flipping is to align with y direction
Areas = flipud( diff( ylines(:) ) ) * diff( xlines(:)' );

% Display more results
disp('Areas enclosed')
disp(Areas)

(抱歉有任何错误,我家里没有 MATLAB 许可证,所以无法运行代码)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-12
    • 2014-02-25
    • 2018-11-10
    • 1970-01-01
    • 2020-09-10
    • 2021-05-28
    • 2016-10-16
    • 2012-03-05
    相关资源
    最近更新 更多