public void SplineToBezier() { var spline = new Spline2( 3, new[] { new SplinePoint2(59.1, 66.8), new SplinePoint2(63.1, 81.7), new SplinePoint2(127.2, 93.7), new SplinePoint2(100.1, 12.9), new SplinePoint2(55.4, 52.8), new SplinePoint2(59.1, 66.8) }, new[] { 0.0, 0.0, 0.0, 0.0, 0.36, 0.65, 1.0, 1.0, 1.0, 1.0 }); var beziers = spline.ToBeziers(); Assert.Equal(3, beziers.Count); AssertClose(new SplinePoint2(59.1, 66.8), beziers[0].Start); AssertClose(new SplinePoint2(63.1, 81.7), beziers[0].Control1); AssertClose(new SplinePoint2(98.6015384615385, 88.3461538461538), beziers[0].Control2); AssertClose(new SplinePoint2(109.037363313609, 75.2010840236686), beziers[0].End); AssertClose(new SplinePoint2(109.037363313609, 75.2010840236686), beziers[1].Start); AssertClose(new SplinePoint2(117.444, 64.612), beziers[1].Control1); AssertClose(new SplinePoint2(109.585, 41.18), beziers[1].Control2); AssertClose(new SplinePoint2(96.1092041015625, 36.5579833984375), beziers[1].End); AssertClose(new SplinePoint2(96.1092041015625, 36.5579833984375), beziers[2].Start); AssertClose(new SplinePoint2(79.8453125, 30.9796875), beziers[2].Control1); AssertClose(new SplinePoint2(55.4, 52.8), beziers[2].Control2); AssertClose(new SplinePoint2(59.1, 66.8), beziers[2].End); }
public void InsertKnot() { var spline = new Spline2( 3, Enumerable.Repeat(new SplinePoint2(0.0, 0.0), 8), new[] { 0.0, 0.0, 0.0, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0 }); spline.InsertKnot(0.5); Assert.Equal(9, spline.ControlPoints.Count()); Assert.Equal(13, spline.KnotValues.Count()); Assert.Equal(new[] { 0.0, 0.0, 0.0, 0.0, 0.2, 0.4, 0.5, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0 }, spline.KnotValues); }
private void RegenerateWPRoute(List <PointLatLngAlt> fullpointlist, PointLatLngAlt HomeLocation) { route.Clear(); homeroute.Clear(); PointLatLngAlt lastpnt = fullpointlist[0]; PointLatLngAlt lastpnt2 = fullpointlist[0]; PointLatLngAlt lastnonspline = fullpointlist[0]; List <PointLatLngAlt> splinepnts = new List <PointLatLngAlt>(); List <PointLatLngAlt> wproute = new List <PointLatLngAlt>(); // add home - this causeszx the spline to always have a straight finish fullpointlist.Add(fullpointlist[0]); for (int a = 0; a < fullpointlist.Count; a++) { if (fullpointlist[a] == null) { continue; } if (fullpointlist[a].Tag2 == "spline") { if (splinepnts.Count == 0) { splinepnts.Add(lastpnt); } splinepnts.Add(fullpointlist[a]); } else { if (splinepnts.Count > 0) { List <PointLatLng> list = new List <PointLatLng>(); splinepnts.Add(fullpointlist[a]); Spline2 sp = new Spline2(HomeLocation); sp.set_wp_origin_and_destination(sp.pv_location_to_vector(lastpnt2), sp.pv_location_to_vector(lastpnt)); sp._flags.reached_destination = true; for (int no = 1; no < (splinepnts.Count - 1); no++) { Spline2.spline_segment_end_type segtype = Spline2.spline_segment_end_type.SEGMENT_END_STRAIGHT; if (no < (splinepnts.Count - 2)) { segtype = Spline2.spline_segment_end_type.SEGMENT_END_SPLINE; } sp.set_spline_destination(sp.pv_location_to_vector(splinepnts[no]), false, segtype, sp.pv_location_to_vector(splinepnts[no + 1])); //sp.update_spline(); while (sp._flags.reached_destination == false) { float t = 1f; //sp.update_spline(); sp.advance_spline_target_along_track(t); // Console.WriteLine(sp.pv_vector_to_location(sp.target_pos).ToString()); list.Add(sp.pv_vector_to_location(sp.target_pos)); } list.Add(splinepnts[no]); } list.ForEach(x => { wproute.Add(x); }); splinepnts.Clear(); lastnonspline = fullpointlist[a]; } wproute.Add(fullpointlist[a]); lastpnt2 = lastpnt; lastpnt = fullpointlist[a]; } } int count = wproute.Count; int counter = 0; PointLatLngAlt homepoint = new PointLatLngAlt(); PointLatLngAlt firstpoint = new PointLatLngAlt(); PointLatLngAlt lastpoint = new PointLatLngAlt(); if (count > 2) { // homeroute = last, home, first wproute.ForEach(x => { counter++; if (counter == 1) { homepoint = x; return; } if (counter == 2) { firstpoint = x; } if (counter == count - 1) { lastpoint = x; } if (counter == count) { homeroute.Points.Add(lastpoint); homeroute.Points.Add(homepoint); homeroute.Points.Add(firstpoint); return; } route.Points.Add(x); }); homeroute.Stroke = new Pen(Color.Yellow, 2); // if we have a large distance between home and the first/last point, it hangs on the draw of a the dashed line. if (homepoint.GetDistance(lastpoint) < 5000 && homepoint.GetDistance(firstpoint) < 5000) { homeroute.Stroke.DashStyle = DashStyle.Dash; } overlay.Routes.Add(homeroute); route.Stroke = new Pen(Color.Yellow, 4); route.Stroke.DashStyle = DashStyle.Custom; overlay.Routes.Add(route); } }