![](/img/trans.png)
[英]Ear Image Processing - Finding the point of intersection of line and curve in MATLAB
[英]Finding an intersection of a curve in Matlab
我准备了右上角显示的问题草图。 基本上,从C点开始,或在草图中用M表示,我想:
如何使用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
相交的点。 要找到光线和线段之间的交点,我们可以执行以下操作。 给定线段的端点处的点,我们称之为p1
和p2
并且射线从A
开始并经过C
,我们求解向量方程p1 + t1*(p2-p1) == A + t2*(CA)
对于标量t1
和t2
。 t1
和t2
的值告诉我们是否存在交叉点以及交叉点发生的位置。
t2 >= 0
且0 <= t1 <= 1
时才存在交点。 D = p1 + t1*(p2-p1)
。 B
只是其中一个点, p1
或p2
取决于所使用的符号。
码:
% 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步 :计算L1
和L2
。
L2
是与AB
正交的AC
的分量。
L1
是的部件AD
平行于AB
。
使用这些知识计算L1
和L2
如下......
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.