Beispiel #1
0
        /// <summary>
        /// Joins a planar xy track curve and a planar height curve
        /// </summary>
        /// <param name="xyTrackCurve"></param>
        /// <param name="hTrackCurve"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static TrackCurve JoinTrackCurves(TrackCurve xyTrackCurve, TrackCurve hTrackCurve, double tolerance)
        {
            // Find common start and end point
            double startVal = FindHighestStartVal(xyTrackCurve, hTrackCurve);
            double endVal   = FindLowestEndVal(xyTrackCurve, hTrackCurve);

            // Divide both curves so that they start and stop at same section
            xyTrackCurve = xyTrackCurve.RemoveStartSegment(startVal);
            xyTrackCurve = xyTrackCurve.RemoveEndSegment(endVal);
            hTrackCurve  = hTrackCurve.RemoveStartSegment(startVal);
            hTrackCurve  = hTrackCurve.RemoveEndSegment(endVal);

            // Divide into normalised parameters
            // Check so that tolerance is ok

            // Create new points
            int nSegments = (int)Math.Ceiling((xyTrackCurve.TrackSections[xyTrackCurve.TrackSections.Count - 1].EndVal -
                                               xyTrackCurve.TrackSections[0].StartVal) / tolerance);
            List <Point3d> hPts = SplitHTrackCurve(hTrackCurve.Curve, nSegments);

            Point3d[] oPts;
            xyTrackCurve.Curve.DivideByCount(nSegments, true, out oPts);
            List <Point3d> xyPts = oPts.ToList();

            List <Point3d> combinedPts = new List <Point3d>();

            for (int i = 0; i < hPts.Count; i++)
            {
                combinedPts.Add(new Point3d(xyPts[i].X, xyPts[i].Y, hPts[i].Z));
            }

            // Interpolate curve
            Curve c = Curve.CreateInterpolatedCurve(combinedPts, 3);

            // Add all track sections
            TrackCurve oTC = new TrackCurve(c);

            foreach (TrackSection ts in xyTrackCurve.TrackSections)
            {
                UpdateXYTrackSection(ts, c, tolerance);
                oTC.AddTrackSection(ts);
            }
            foreach (TrackSection ts in hTrackCurve.TrackSections)
            {
                UpdateHTrackSection(ts, hTrackCurve.Curve, c, tolerance);
                oTC.AddTrackSection(ts);
            }

            // Update section directions
            oTC.UpdateSectionDirection();

            return(oTC);
        }
Beispiel #2
0
        private TrackCurve CreateXYProfileTrackCurve(string[,] xyProfileData, double tol)
        {
            List <Curve>        crvs = new List <Curve>();
            List <TrackSection> tcs  = new List <TrackSection>();

            for (int i = 0; i < xyProfileData.GetLength(0); i++)
            {
                if (xyProfileData[i, 1] == "RL")
                {
                    crvs.Add(CreateXYLine(xyProfileData, i).ToNurbsCurve());
                }

                else if (xyProfileData[i, 1] == "C")
                {
                    crvs.Add(CreateXYArc(xyProfileData, i).ToNurbsCurve());
                }

                else if (xyProfileData[i, 1] == "ÖK")
                {
                    crvs.Add(CreateXYClothoid(xyProfileData, i, tol).ToNurbsCurve());
                }

                // Create track sections
                if (xyProfileData[i, 2].StartsWith("KM"))
                {
                    TrackSection tc = null;

                    if (xyProfileData[i, 1] != "")
                    {
                        if (CreateTrackSection(xyProfileData[i, 2], crvs[crvs.Count - 1].PointAtStart, crvs[crvs.Count - 1], out tc))
                        {
                            tcs.Add(tc);
                        }

                        else // Maybe add another check here
                        if (CreateTrackSectionConnection(xyProfileData[i, 2], crvs[crvs.Count - 1].PointAtEnd, crvs[crvs.Count - 1], out tc))
                        {
                            tcs.Add(tc);
                        }
                    }
                }
            }


            Curve[] jCrvs = Curve.JoinCurves(crvs);
            //CurveDebug = jCrvs[0];                      //DEBUG
            if (jCrvs.Length > 1)
            {
                throw new Exception("Unable to join curves");
            }
            else
            {
                // Join and add track sections
                TrackCurve tc = new TrackCurve(jCrvs[0]);
                tc.AddTrackSection(tcs);

                // Vector from start point of curve to origin
                Vector3d v = new Vector3d(jCrvs[0].PointAtStart);
                v.Reverse();
                tc.Translate(v);

                return(tc);
            }
        }