简体   繁体   English

2 条线的交点 - 数值分析

[英]Intersection of 2 lines - numerical analysis

I have 2 two-dimensional arrays that represent 2 lines/curves, something like:我有 2 个代表 2 条线/曲线的二维数组,例如:

(y1,t1) (y2,t2) ... (yN, tN)

and

(Y1, t1) (Y2, t2) ... (YN, tN)

My goal is to find the last point from the beginning of the array just before the intersection of 2 lines/curves.我的目标是在 2 条线/曲线的交点之前从数组的开头找到最后一个点。

I tried comparing我试着比较

if ( (y1 > Y1 && y2 < Y2) || (y1 < Y1 && y2 > Y2) || (y1 == Y2) )

in order t0 find intersection but it does not work or verifying result is very difficult due to large number of points.为了 t0 找到交点但它不起作用或由于大量点而验证结果非常困难。

Is there nay elegant solution in C# using open source numerical analysis library that all I need to do is feed the 2 arrays into the function and get intersection?在 C# 中是否有使用开源数值分析库的优雅解决方案,我需要做的就是将 2 个数组输入函数并获得交集?

On c# your algorithm looks like:在 C# 上,您的算法如下所示:

public void FindFirstIntersection(int[,] curve1, int[,] curve2)
    {
        for (var i = 0; i < curve1.Length - 1; i++)
        {
            var curve1Point = curve1[i, 0];
            var curve2Point = curve2[i, 0];

            var curve1NextPoint = curve1[i + 1, 0];
            var curve2NextPoint = curve2[i + 1, 0];

            if (curve1Point > curve2Point && curve1NextPoint < curve2NextPoint ||
                curve1Point < curve2Point && curve1NextPoint > curve2NextPoint ||
                curve1Point == curve2Point)
            {
                //Do smth
            }
        }
    }

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

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