public Vector2 Do(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float progress) { Dictionary <double, double> points = new Dictionary <double, double> { { p0.x, p0.y }, { p1.x, p1.y }, { p2.x, p2.y }, { p3.x, p3.y } }; SplineInterpolator splineInterpolator = new SplineInterpolator(points); return(splineInterpolator.GetValue(progress)); }
protected void Page_Load(object sender, EventArgs e) { var r = 1000; var known = new Dictionary <double, double> { { 0.0, 0.0 }, { 0.1, 0.1 }, { 20.0, 0.25 * r }, { 120.0, 0.75 * r } }; foreach (var pair in known) { //Response.Write(String.Format("{0:0.000}\t{1:0.000}", pair.Key, pair.Value) + "<br/>"); } var scaler = new SplineInterpolator(known); var start = known.First().Key; var end = known.Last().Key; var step = (end - start) / 100; var points = new Dictionary <double, double>(); //chart.Series[0]. for (var x = start; x <= end; x += step) { var y = scaler.GetValue(x); points.Add(x, y); if (x > Double.MinValue && y >= Double.MinValue && x < Double.MaxValue && y < Double.MaxValue) { //Response.Write(String.Format("\t\t{0:0.000}\t{1:0.000}", x, y) + "<br/>"); chart.Series[0].Points.AddXY(x, y); } } DisplayDataTables(); FillChart2(); }
private void OnDrawGizmos() { Dictionary <double, double> known = new Dictionary <double, double> { { 0, 0 }, { 1, 10 }, { 7, 20 }, { 14, -1 }, { 15, 15 }, { 20, -10 }, { 25, -1 }, { 27, -40 }, { 21, 30 }, }; foreach (var pair in known) { Gizmos.DrawSphere(new Vector3((float)pair.Key, (float)pair.Value, 0), 1); // Debug.WriteLine($"{pair.Key:0.000}\t{pair.Value:0.000}"); } SplineInterpolator scaler = new SplineInterpolator(known); double start = known.First().Key; double end = known.Last().Key; double step = (end - start) / 500; for (double x = start; x <= end; x += step) { try { double y = scaler.GetValue(x); Gizmos.DrawSphere(new Vector3((float)x, (float)y, 0), 1); } catch (Exception e) { } // Debug.WriteLine($"\t\t{x:0.000}\t{y:0.000}"); } }