繁体   English   中英

在Matlab中找到一条曲线的交点

[英]Finding an intersection of a curve in Matlab

我有一个几何问题,如下图所示, 在此输入图像描述

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

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

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

下面是数字数据集

对于蓝点(在图中标记为“实际”)

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

对于标记为“预测”的那个

   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步 :找到B点和D点。

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

  • 当且仅当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

L2是与AB正交的AC的分量。

L1是的部件AD平行于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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM