Beispiel #1
0
        private void PlotBezierTangentByDegree(List <GPoint> points)
        {
            base.Axes.Add(new OxyPlot.Axes.LinearAxis
            {
                Title    = "Tangent of Bezier(Degree)",
                Position = OxyPlot.Axes.AxisPosition.Left
            });
            AddZeroLineAnnotation();

            OxyPlot.Series.LineSeries ls = new OxyPlot.Series.LineSeries()
            {
                Title        = "Tangent of Bezier(Degree)",
                MarkerType   = ShowMarker ? MarkerType.None : MarkerType.Plus,
                MarkerStroke = OxyPlot.OxyColors.Blue
            };

            int        degree  = points.Count - 1;
            NURBSCurve bspline = new NURBSCurve(points, degree);

            for (double u = 0; u <= 1.0; u += 0.01)
            {
                double tangent = bspline.TangentByDegree(u);
                ls.Points.Add(new OxyPlot.DataPoint(u * 100.0, tangent));
            }

            base.Series.Add(ls);
        }
Beispiel #2
0
        private void PlotCurveManeuver(List <GPoint> points, double curveLength, int degree)
        {
            if (points.Count < 2)
            {
                return;
            }

            double        scale      = (CurvatureUnit == CurvatureUnit.Centimeter) ? 0.01 : 1.0; // 1/cm or 1/m
            List <GPoint> curvatures = new List <GPoint>();
            NURBSCurve    bspline    = new NURBSCurve(points, degree);

            for (double u = 0.01; u < 1.0 - 0.01; u += 0.01)
            {
                double curvature         = bspline.Curvature(u);
                double distanceFromStart = curveLength * u;
                curvatures.Add(new GPoint(u * 100.0, curvature * scale, weight: distanceFromStart));
            }

            List <GPoint> simplified        = SimplifyPolyline(curvatures, CurveManeuverParameter.CurveMinDistance);
            List <GPoint> curvaturManeuvers = PolylineSimplication.SimplifyHeadingChange(simplified.ToArray(), CurveManeuverParameter.YTolerance);

            List <GPoint> maneuvers = new List <GPoint>();

            foreach (var p in curvaturManeuvers)
            {
                int index = Weight2Index(p, curveLength, points.Count);
                maneuvers.Add(points[index]);
            }

            AddScatterSeries(maneuvers, "Maneuvers");
        }
Beispiel #3
0
        private void AddBezierByNURBS(List <GPoint> points)
        {
            if (points.Count() < 3)
            {
                return;
            }

            int degree = points.Count - 1;
            var ls     = new OxyPlot.Series.LineSeries()
            {
                MarkerType   = ShowMarker ? MarkerType.None : MarkerType.Plus,
                MarkerStroke = OxyPlot.OxyColors.Blue
            };

            double duration = Util.Util.MeasureExecTime(() =>
            {
                const int INTERVAL_NUM = 100;
                double step            = 1.0 / INTERVAL_NUM;
                NURBSCurve bspline     = new NURBSCurve(points, degree);
                for (double t = 0; t < 1.0; t += step)
                {
                    GPoint p = bspline.NonRationalBSpline(t);
                    ls.Points.Add(new OxyPlot.DataPoint(p.X, p.Y));
                }
            });

            ls.Title = $"NURBS(Bezier-{degree})({duration:0.###}ms)";
            base.Series.Add(ls);
        }
Beispiel #4
0
        private void AddBSplineByNURBS(List <GPoint> points, double curveLength)
        {
            if (points.Count() < 3)
            {
                return;
            }

            var ls = new OxyPlot.Series.LineSeries()
            {
                MarkerType   = ShowMarker ? MarkerType.None : MarkerType.Plus,
                MarkerStroke = OxyPlot.OxyColors.Blue
            };

            int    degree   = SplineDegree(points);
            double duration = Util.Util.MeasureExecTime(() =>
            {
                NURBSCurve bspline = new NURBSCurve(points, degree);
                for (double u = 0; u <= 1.0; u += 0.01)
                {
                    GPoint p = bspline.NonRationalBSpline(u);
                    ls.Points.Add(new OxyPlot.DataPoint(p.X, p.Y));
                }
            });

            ls.Title = $"NURBS({degree})[len={curveLength:0.#}]({duration:0.###}ms)";
            base.Series.Add(ls);
        }
        public void NURBSCurve()
        {
            double[][] pts     = null;
            KnotSet    knotset = null;
            int        degree  = int.MinValue;
            NURBSCurve bSpline = null;

            double[] weights = null;

            pts = new double[][]
            {
                new double[] { 0, 0, 0 },
                new double[] { 2, 4, 0 },
                new double[] { 4, 0, 0 },
                new double[] { 6, 4, 0 },
            };
            knotset = new KnotSet(new double[] { 0, 0, 0, 0, 1, 1, 1, 1 });
            weights = new double[] { 1, 1, 1, 1 };
            degree  = 3;

            bSpline = new NURBSCurve(pts, knotset, weights, degree);
        }
Beispiel #6
0
        private void PlotBSplineRawCurvatureByNURBS(List <GPoint> points, double curvelength)
        {
            // curvature
            base.Axes.Add(new OxyPlot.Axes.LinearAxis
            {
                Title    = (CurvatureUnit == CurvatureUnit.Meter) ? "Curvature(1/m)" : "Curvature(1/cm)",
                Position = OxyPlot.Axes.AxisPosition.Left
            });
            AddZeroLineAnnotation();

            int degree = SplineDegree(points);

            OxyPlot.Series.LineSeries ls = new OxyPlot.Series.LineSeries()
            {
                MarkerType   = ShowMarker ? MarkerType.None : MarkerType.Plus,
                MarkerStroke = OxyPlot.OxyColors.Blue
            };

            List <GPoint> curvatures = new List <GPoint>();
            double        duration   = Util.Util.MeasureExecTime(() =>
            {
                double scale       = (CurvatureUnit == CurvatureUnit.Centimeter) ? 0.01 : 1.0; // 1/cm or 1/m
                NURBSCurve bspline = new NURBSCurve(points, degree);
                for (double u = 0.01; u < 1.0 - 0.01; u += 0.01)
                {
                    double curvature = bspline.Curvature(u) * scale;
                    double dist      = curvelength * u;
                    ls.Points.Add(new OxyPlot.DataPoint(dist, curvature));
                    curvatures.Add(new GPoint(dist, curvature, weight: dist));
                }
            });

            ls.Title = $"NURBS({degree}) Curvature({duration:0.###}ms)";
            base.Series.Add(ls);

            PlotSimplifiedPolyline(curvatures);
            PlotManeuverOnCurvatureCurve(curvatures);
        }
        public void ParameterAt()
        {
            double[][] pts     = null;
            double[]   weights = null;
            KnotSet    knotset = null;
            int        degree  = int.MinValue;
            NURBSCurve nurbs   = null;

            double[] r, a;
            double   t, e;

            pts = new double[][]
            {
                new double[] { 0, 0, 0 },
                new double[] { 2, 4, 0 },
                new double[] { 4, 0, 0 },
            };

            weights = new double[] { 1, 3, 1 };
            knotset = new KnotSet(new double[] { 0, 0, 0, 1, 1, 1 });
            degree  = 2;
            nurbs   = new NURBSCurve(pts, knotset, weights, degree);
            t       = 0.5;
            a       = new double[] { 2, 3, 0 };
            r       = nurbs.ParameterAt(t);

            Assert.IsTrue(a.SequenceEqual(r));


            pts = new double[][]
            {
                new double[] { 0, 0, 0 },
                new double[] { 2, 4, 0 },
                new double[] { 4, 0, 0 },
            };

            weights = new double[] { 1, 3, 1 };
            knotset = new KnotSet(new double[] { 0, 0, 0, 1, 1, 1 });
            degree  = 2;
            nurbs   = new NURBSCurve(pts, knotset, weights, degree);
            t       = 1;
            a       = new double[] { 4, 0, 0 };
            r       = nurbs.ParameterAt(t);
            e       = 0.0001;

            Assert.IsTrue(a.SequenceEqual(r, e));


            pts = new double[][]
            {
                new double[] { 0, 0, 0 },
                new double[] { 2, 4, 0 },
                new double[] { 6, 4, 0 },
            };
            weights = new double[] { 1, 1, 1 };
            knotset = new KnotSet(new double[] { 0, 0, 0, 1, 1, 1 });
            degree  = 2;
            nurbs   = new NURBSCurve(pts, knotset, weights, degree);
            t       = 1;
            a       = new double[] { 6, 4, 0 };
            r       = nurbs.ParameterAt(t);
            e       = 0.0001;

            Assert.IsTrue(a.SequenceEqual(r, e));


            pts = new double[][]
            {
                new double[] { 0.0, 0.0, 0.0 },
                new double[] { 4.0, 5.0, 0.0 },
                new double[] { 6.0, 1.0, 0.0 },
                new double[] { 9.0, 5.0, 0.0 },
                new double[] { 11.0, 3.0, 0.0 },
                new double[] { 16.0, 4.0, 0.0 },
            };

            weights = new double[] { 1, 3, 1, 3, 1, 2 };
            knotset = new KnotSet(new double[] { 0, 0, 0, 0, 1d / 3d, 2d / 3d, 1, 1, 1, 1 });
            degree  = 3;
            nurbs   = new NURBSCurve(pts, knotset, weights, degree);
            t       = 0.3;
            a       = new double[] { 5.52901, 3.849042, 0.0 };
            r       = nurbs.ParameterAt(t);

            e = 0.0001;
            Assert.IsTrue(Math.Abs(a[0] - r[0]) < e);
            Assert.IsTrue(Math.Abs(a[1] - r[1]) < e);
            Assert.IsTrue(Math.Abs(a[2] - r[2]) < e);


            pts = new double[][]
            {
                new double[] { 0.0, 0.0, 0.0 },
                new double[] { 4.0, 5.0, 0.0 },
                new double[] { 6.0, 1.0, 0.0 },
                new double[] { 9.0, 5.0, 0.0 },
                new double[] { 11.0, 3.0, 0.0 },
                new double[] { 16.0, 4.0, 0.0 },
            };

            weights = new double[] { 1, 3, 1, 3, 1, 2 };
            knotset = new KnotSet(new double[] { 0, 0, 0, 0, 1d / 3d, 2d / 3d, 1, 1, 1, 1 });
            degree  = 3;
            nurbs   = new NURBSCurve(pts, knotset, weights, degree);
            t       = 0.3948;
            a       = new double[] { 6.9053986159719711, 3.6972003072706183, 0.0 };
            r       = nurbs.ParameterAt(t);

            e = 0.0001;
            Assert.IsTrue(r.SequenceEqual(a, e));


            pts = new double[][]
            {
                new double[] { 0.0, 0.0, 0.0 },
                new double[] { 4.0, 5.0, 0.0 },
                new double[] { 6.0, 1.0, 0.0 },
                new double[] { 9.0, 5.0, 0.0 },
                new double[] { 11.0, 3.0, 0.0 },
                new double[] { 16.0, 4.0, 0.0 },
            };

            weights = new double[] { 1, 3, 1, 3, 1, 2 };
            knotset = new KnotSet(new double[] { 0, 0, 0, 0, 1d / 3d, 2d / 3d, 1, 1, 1, 1 });
            degree  = 3;
            nurbs   = new NURBSCurve(pts, knotset, weights, degree);
            t       = 1;
            a       = new double[] { 16, 4, 0 };
            r       = nurbs.ParameterAt(t);

            e = 0.0001;
            Assert.IsTrue(r.SequenceEqual(a, e));
        }