/// <summary> /// 旧版,没有dkcode2 /// </summary> /// <param name="idx"></param> /// <param name="dkcode"></param> /// <param name="fromM"></param> /// <param name="toM"></param> /// <param name="isA"></param> /// <param name="isR"></param> /// <param name="isD"></param> /// <param name="num"></param> /// <param name="m"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="stepm"></param> /// <param name="otherDKCode"></param> public CRailwayLine(int idx, string dkcode, double fromM, double toM, bool isA, bool isR, bool isD, int num, double[] m, double[] x, double[] y, double[] z, double stepm = 10, string otherDKCode = "") { mIndex = idx; mStart = fromM; mEnd = toM; if (mStart < mEnd) { mIsReverse = false; } else { mIsReverse = true; } mDKCode = dkcode; mIsAuxiliary = isA; mIsRight = isR; mIsDouble = isD; if (mIsDouble) { mOffset = 2.5; // 根据济青铁路轨道间距5米测算 } else { mOffset = 5.4; // 线杆偏移位置 } mStepm = Math.Max(1, Math.Abs(stepm)); // //mFromID = fromID; //mToID = toID; // 利用stepM重采样,0513,FIXED,采样非10米时,mPointNum计算错误 mLength = m[num - 1] - m[0]; if (mLength < 2 * mStepm) { mPointNum = 2; } else { mPointNum = (int)((mLength - 2 * stepm) / stepm) + 3; //最后一段一般大于10米,避免最后一段过短, } meter = new double[mPointNum]; meter[0] = m[0]; meter[mPointNum - 1] = m[num - 1]; //for (int j = 0; j < num - 1; j++) // if (m[j] >= m[j+ 1]) // Console.WriteLine("mileage error " + m[j] + "\t" + m[j+1]); for (int i = 1; i < mPointNum - 1; i++) { meter[i] = meter[i - 1] + mStepm; } longitude = CubicSpline.Compute(num, m, x, meter); latitude = CubicSpline.Compute(num, m, y, meter); altitude = CubicSpline.Compute(num, m, z, meter); //for (int i = 0; i < mPointNum - 1; i += (int)(1000/mStepm)) // mBBoxList.Add(new RectangleF((float)(longitude[i] - 0.01),(float)(latitude[i] -0.01),0.02f,0.02f)); //if (mPointNum % 100 > 20) // mBBoxList.Add(new RectangleF((float)(longitude[mPointNum -1] - 0.01), (float)(latitude[mPointNum -1] - 0.01), 0.02f, 0.02f)); // RectangleF rec = mBBoxList[0]; //CoordinateConverter.LatLonToUTMXYList(mPointNum, latitude, longitude, out utmX, out utmY); mOtherDKCode = otherDKCode; CoordinateConverter.LatLonToOffsetYawList(latitude, longitude, 90, mOffset, out mOffsetX, out mOffsetY, out heading); //CoordinateConverter.LatLonToUTMXYList(mPointNum, latitudeMars, longitudeMars, out utmXMars, out utmYMars); //CoordinateConverter.LatLonOffest(longitude,latitude,heading,90,mOffset,out mOffsetX,out mOffsetY ); #if DEBUG validateHeading(); #endif }
/// <summary> /// Static all-in-one method to fit the splines and evaluate at X coordinates. /// </summary> /// <param name="num">Input. Real Lenth of X. Values in X must in ascend Order</param> /// <param name="x">Input. X coordinates to fit.</param> /// <param name="y">Input. Y coordinates to fit.</param> /// <param name="xs">Input. X coordinates to evaluate the fitted curve at.</param> /// <param name="startSlope">Optional slope constraint for the first point. Single.NaN means no constraint.</param> /// <param name="endSlope">Optional slope constraint for the final point. Single.NaN means no constraint.</param> /// <param name="debug">Turn on console output. Default is false.</param> /// <returns>The computed y values for each xs.</returns> public static double[] Compute(int num, double[] x, double[] y, double[] xs, double startSlope = double.NaN, double endSlope = double.NaN, bool debug = false) { CubicSpline spline = new CubicSpline(); return(spline.FitAndEval(num, x, y, xs, startSlope, endSlope, debug)); }