X,Y线偏移,无自交点

时间:2018-11-15 22:00:43

标签: c#

我正在尝试更正此C#代码,该代码应创建没有自相交的偏移线。它根据探测点(x,y坐标)和输入的偏移距离来计算其偏移量。 Y偏移量组件有效,而X无效。任何帮助或见识将无限地感激。 这是执行此过程的代码部分。

private void OffsetData(double R)
{
    double Increment = 0.01;
    X2 = (double[])X.Clone();  // copy original

    // apply a circle to every measured point and
    // push neighbor points out beyond the circle
    for (int i = 0; i < Npts; i++)
    {
        // offset forward
        double k = i + Increment;
        while (k < Npts - 1)
        {
            // determine how far away the neighbor is in Y
            double dy = (k - i) * DeltaY;

            // compute extent outward in X
            double d = R * R - dy * dy;
            if (d < 0) break; // beyond circel radius - no need to go further
            double dx = Math.Sqrt(d);

       //interpolate to find X[k] where K is a fraction
       int ki = (int)k;
       double Xk = X[ki] + (X[ki + 1] - X[ki]) * (k - ki);

       // if x value is within circle push out
       if (X2[i] < Xk + dx) X2[i] = Xk + dx;
       k += Increment;
       }
        // offset backward
        k = i - Increment;
        while (k > 0)
        {
            // determine how far away the neighbor is in Y
            double dy = (k - i) * DeltaY;

            // compute extent outward in X
            double d = R * R - dy * dy;
            if (d < 0) break; 

//超出圆弧半径-无需进一步                 double dx = Math.Sqrt(d);

       //interpolate to find X[k] where K is a fraction
       int ki = (int)k;
       double Xk = X[ki] + (X[ki + 1] - X[ki]) * (k - ki);

            // if x value is within circle push out
            if (X2[i] < Xk + dx) X2[i] = Xk + dx;
            k -= Increment;
        }
    }
}

0 个答案:

没有答案