public class PointF
{
public float X { get; set; }
public float Y { get; set; }
}
public Dictionary<string,string> Getpoints(string[] args)
{
Dictionary<string,string>dic=new Dictionary<string,string>();
PointF[] pointList = new PointF[] { new PointF {X=1.3F, Y=2.4F}, new PointF { X = 2.0F, Y=3.00F }, new PointF { X = 12.3F, Y=13.2F } };
PointF[] aa = draw_bezier_curves(pointList, pointList.Length, 0.001F); // 在起点和终点之间画1/0.001=1000个点
foreach (PointF item in aa)
{
dic.Add(item.X.ToString(),item.Y.ToString());
}
return dic;
}
public static PointF[] draw_bezier_curves(PointF[] points, int count, float step)
{
List<PointF> bezier_curves_points = new List<PointF>();
float t = 0F;
do
{
PointF temp_point = bezier_interpolation_func(t, points, count); // 计算插值点
t += step;
bezier_curves_points.Add(temp_point);
}
while (t <= 1 && count > 1); // 一个点的情况直接跳出.
return bezier_curves_points.ToArray(); // 曲线轨迹上的所有坐标点
}
private static PointF bezier_interpolation_func(float t, PointF[] points, int count)
{
if (points.Length < 1) // 一个点都没有
throw new ArgumentOutOfRangeException();
PointF[] tmp_points = new PointF[count];
for (int i = 1; i < count; ++i)
{
for (int j = 0; j < count - i; ++j)
{
if (i == 1)
{
float x1= (float)(points[j].X * (1 - t) + points[j + 1].X * t);
float y1= (float)(points[j].Y * (1 - t) + points[j + 1].Y * t);
tmp_points[j] = new PointF { X = x1, Y = y1 };
continue;
}
float x = (float)(tmp_points[j].X * (1 - t) + tmp_points[j + 1].X * t);
float y = (float)(tmp_points[j].Y * (1 - t) + tmp_points[j + 1].Y * t);
tmp_points[j] = new PointF { X = x, Y = y };
}
}
return tmp_points[0];
}