在Matlab中找到曲线的交点

Finding an intersection of a curve in Matlab

我有一个几何问题,如下图所示,

我已经准备好右上角显示的问题草图。基本上,从 C 点开始,或在草图中表示为 M,我想:

  1. 测量 L2,即 C 点到相关极点(黑线)的距离。 C的坐标是已知的。极点基本上是从原点 运行 开始,即 {0,0} 超过 360 度每 30 度向外移动一次。极点将始终与坐标也已知的蓝点相交。
  2. 测量L1,它是从原点到一个点的距离,该点是从L3与蓝色曲率的交点的距离获得的。很难解释,但我希望草图能有所帮助。

如何使用 Matlab 解决这个问题?

下面是数字数据集

对于蓝色点(在图中标记为 "actual")

Theta(deg)      x          y
================================
       0    1.0148         0
   20.0000    0.9397    0.3420
   40.0000    0.8042    0.6748
   60.0000    0.5727    0.9919
   80.0000    0.2073    1.1757
  100.0000   -0.2073    1.1757
  120.0000   -0.5727    0.9919
  140.0000   -0.8042    0.6748
  160.0000   -0.9397    0.3420
  180.0000   -1.0148         0
  200.0000   -0.9397   -0.3420
  220.0000   -0.8042   -0.6748
  240.0000   -0.5727   -0.9919
  260.0000   -0.2073   -1.1757
  280.0000    0.2073   -1.1757
  300.0000    0.5727   -0.9919
  320.0000    0.8042   -0.6748
  340.0000    0.9397   -0.3420
  360.0000    1.0148         0

对于标记为 "predicted"

的那个
   x-pred     y-pred
===========================
    1.0953    0.2897
    1.0292    0.6399
    0.8390    0.9013
    0.5476    1.1899
    0.1902    1.2300
   -0.1902    1.3091
   -0.5476    1.0693
   -0.8390    0.9247
   -1.0292    0.4744
   -1.0953    0.2070
   -1.0292   -0.2885
   -0.8390   -0.5168
   -0.5476   -0.8711
   -0.1902   -0.9193
    0.1902   -1.0086
    0.5476   -0.8278
    0.8390   -0.6483
    1.0292   -0.3125
    1.0953   -0.0000

任何想法将不胜感激。

提前致谢。

步骤 1:找到点 BD.

D是蓝色曲线中的线段与射线AC相交的点。要找到射线和线段之间的交点,我们可以执行以下操作。给定我们称为 p1p2 的线段端点处的点以及从 A 开始并通过 C 的射线,我们求解向量方程 p1 + t1*(p2-p1) == A + t2*(C-A) 表示标量 t1t2t1t2 的值告诉我们是否存在交集,以及交集发生的位置。

  • 有交集当且仅当t2 >= 00 <= t1 <= 1.
  • 如果有交集,那么它出现在D = p1 + t1*(p2-p1)

B 只是要点之一,p1p2 取决于所使用的符号。

代码:

% Assuming C and A are represented as 1x2 matrices.
% Assuming blue is an Nx2 matrix containing the x-y coordinates of
%   the points in the blue curve in order of increasing theta.

% Search for intersecting line segment to find B and D
N = size(blue,1);
for bidx = 1:N
    p1 = blue(bidx,:);
    p2 = blue(mod(bidx,N)+1,:);
    % solve for t1 and t2
    t = [(p2-p1).' (A-C).']\((A-p1).');
    % if we find intersection we are done.
    if t(2) >= 0 && t(1) >= 0 && t(1) <= 1
        D = p1 + t(1)*(p2-p1);
        B = p2;
        break;
    end
end

步骤 2:计算 L1L2.

L2AC 正交于 AB 的分量。

L1AD 平行于 AB 的分量。

使用这些知识计算 L1L2 如下...

AB = B-A;
AC = C-A;
AD = D-A;
% projection of vector X onto vector Y.
proj = @(X,Y) Y * dot(X,Y)/dot(Y,Y);

% get the desired distances
L2 = norm(AC - proj(AC,AB));
L1 = norm(proj(AD,AB));