/// <summary> /// 按照匀速运动模式计算贝塞尔插值点 /// </summary> /// <param name="bezier">控制点</param> /// <param name="t1">比例</param> /// <returns></returns> private BezierPoints LerpBezierCurve(BezierPoints bezier, float t1) { BezierPoints ret = new BezierPoints(); float x1 = bezier.pts[0].X; float bx1 = bezier.pts[1].X; float bx2 = bezier.pts[2].X; float x2 = bezier.pts[3].X; float y1 = bezier.pts[0].Y; float by1 = bezier.pts[1].Y; float by2 = bezier.pts[2].Y; float y2 = bezier.pts[3].Y; float t0 = 0; float u0 = 1.0f - t0; float u1 = 1.0f - t1; float qxa = x1 * u0 * u0 + bx1 * 2 * t0 * u0 + bx2 * t0 * t0; float qxb = x1 * u1 * u1 + bx1 * 2 * t1 * u1 + bx2 * t1 * t1; float qxc = bx1 * u0 * u0 + bx2 * 2 * t0 * u0 + x2 * t0 * t0; float qxd = bx1 * u1 * u1 + bx2 * 2 * t1 * u1 + x2 * t1 * t1; float qya = y1 * u0 * u0 + by1 * 2 * t0 * u0 + by2 * t0 * t0; float qyb = y1 * u1 * u1 + by1 * 2 * t1 * u1 + by2 * t1 * t1; float qyc = by1 * u0 * u0 + by2 * 2 * t0 * u0 + y2 * t0 * t0; float qyd = by1 * u1 * u1 + by2 * 2 * t1 * u1 + y2 * t1 * t1; float xa = qxa * u0 + qxc * t0; float xb = qxa * u1 + qxc * t1; float xc = qxb * u0 + qxd * t0; float xd = qxb * u1 + qxd * t1; float ya = qya * u0 + qyc * t0; float yb = qya * u1 + qyc * t1; float yc = qyb * u0 + qyd * t0; float yd = qyb * u1 + qyd * t1; ret.pts[0].X = xa; ret.pts[1].X = xb; ret.pts[2].X = xc; ret.pts[3].X = xd; ret.pts[0].Y = ya; ret.pts[1].Y = yb; ret.pts[2].Y = yc; ret.pts[3].Y = yd; return ret; }
private BezierPoints[] PreBeziers(int num) { BezierPoints[] beziers = new BezierPoints[num]; for (int i = 0; i < num; i++) { beziers[i] = new BezierPoints(); } return beziers; }
private BezierPoints[] drawP(string[] keyPointList) { BezierPoints[] beziers = new BezierPoints[1]; beziers[0] = bezierPie(keyPointList, 0, 2); return beziers; }
private BezierPoints[] drawXG(string[] keyPointList) { BezierPoints[] beziers = new BezierPoints[2]; beziers[0] = bezierPie(keyPointList, 0, 2); beziers[1] = bezierLine(keyPointList, 2, 3); return beziers; }
private BezierPoints[] drawHZZZ(string[] keyPointList) { BezierPoints[] beziers = new BezierPoints[4]; beziers[0] = bezierLine(keyPointList, 0, 1); beziers[1] = bezierLine(keyPointList, 1, 2); beziers[2] = bezierLine(keyPointList, 2, 3); beziers[3] = bezierLine(keyPointList, 3, 4); return beziers; }
private BezierPoints[] drawDT(string[] keyPointList) { BezierPoints[] beziers = new BezierPoints[] { new BezierPoints() }; PointF base0 = SplitKeyPoints(keyPointList, 0); PointF base1 = SplitKeyPoints(keyPointList, 1); PointF base2 = SplitKeyPoints(keyPointList, 2); beziers[0].pts[0] = new PointF( base0.X * 0.6f + base1.X * 0.4f, base0.Y * 0.0f + base1.Y * 1.0f); beziers[0].pts[1] = new PointF( base1.X * 0.5f + base2.X * 0.5f, base1.Y * 0.4f + base2.Y * 0.6f); beziers[0].pts[2] = beziers[0].pts[1]; beziers[0].pts[3] = beziers[0].pts[1]; return beziers; }
private BezierPoints[] drawD(string[] keyPointList) { BezierPoints[] beziers = new BezierPoints[] { new BezierPoints() }; beziers[0].pts[0] = SplitKeyPoints(keyPointList, 0); beziers[0].pts[3] = SplitKeyPoints(keyPointList, 2); beziers[0].pts[1] = new PointF( beziers[0].pts[0].X * 0.3f + beziers[0].pts[3].X * 0.7f, beziers[0].pts[0].Y * 0.5f + beziers[0].pts[3].Y * 0.5f); beziers[0].pts[2] = beziers[0].pts[1]; return beziers; }
private BezierPoints bezierPie(string[] keyPoints, int idxStart, int idxEnd) { BezierPoints pie = new BezierPoints(); pie.pts[0] = SplitKeyPoints(keyPoints, idxStart); pie.pts[3] = SplitKeyPoints(keyPoints, idxEnd); PointF base0 = SplitKeyPoints(keyPoints, idxStart + 1); pie.pts[1] = new PointF( pie.pts[0].X * 0.2f + base0.X * 0.8f, base0.Y); pie.pts[2] = new PointF( base0.X, base0.Y * 0.7f + pie.pts[3].Y * 0.3f); return pie; }
private BezierPoints bezierLine(string[] keyPoints, int idxStart, int idxEnd) { BezierPoints line = new BezierPoints(); line.pts[0] = SplitKeyPoints(keyPoints, idxStart); line.pts[3] = SplitKeyPoints(keyPoints, idxEnd); if (Math.Abs(line.pts[3].X - line.pts[0].X) < 8) line.pts[3].X = line.pts[0].X; if (Math.Abs(line.pts[3].Y - line.pts[0].Y) < 8) line.pts[3].Y = line.pts[0].Y; LinearLerp(line.pts[0], line.pts[3], ref line.pts[1], ref line.pts[2]); //line.pts[1].X = line.pts[0].X * 0.67f + line.pts[3].X * 0.33f; //line.pts[1].Y = line.pts[0].Y * 0.67f + line.pts[3].Y * 0.33f; //line.pts[2].X = line.pts[0].X * 0.33f + line.pts[3].X * 0.67f; //line.pts[2].Y = line.pts[0].Y * 0.33f + line.pts[3].Y * 0.67f; return line; }