Bezier 曲线的控制多边形有 4 个控制点, P 0 P_0 P0?、 P 1 P_1 P1?、 P 2 P_2 P2? 和 P 3 P_3 P3?, Bezier 曲线是三次多项式,称为三次 Bezier 曲线,
P
(
t
)
=
∑
i
=
0
3
P
i
B
i
,
3
(
t
)
=
(
1
?
t
)
3
P
0
+
3
t
(
1
?
t
)
2
P
1
+
3
t
2
(
1
?
t
)
P
2
+
t
3
P
3
\begin{equation} P(t) = \sum_{i=0}^{3}P_i B_{i, 3}(t) = (1-t)^3 P_0 + 3t(1-t)^2P_{1} + 3t^2(1-t)P_2 + t^3P_3 \end{equation}
P(t)=i=0∑3?Pi?Bi,3?(t)=(1?t)3P0?+3t(1?t)2P1?+3t2(1?t)P2?+t3P3???
B
0
,
3
(
t
)
=
(
1
?
t
)
3
B
1
,
3
(
t
)
=
3
t
(
1
?
t
)
2
B
2
,
3
(
t
)
=
3
t
2
(
1
?
t
)
B
3
,
3
(
t
)
=
t
3
B_{0, 3}(t) = (1-t)^3 \\ B_{1, 3}(t) = 3t(1-t)^2 \\ B_{2, 3}(t) = 3t^2(1-t) \\ B_{3, 3}(t) = t^3
B0,3?(t)=(1?t)3B1,3?(t)=3t(1?t)2B2,3?(t)=3t2(1?t)B3,3?(t)=t3
double step = 0.01;
for (double t = 0.0; t < 1.0; t += step)
{
// 计算 基函数
p.x = 0;
p.y = 0;
double B03 = (1 - t) * (1 - t) * (1 - t);
double B13 = 3 * t * (1 - t) * (1 - t);
double B23 = 3 * t * t * (1 - t);
double B33 = t * t * t;
p.x += B03 * P[0].x + B13 * P[1].x + B23 * P[2].x + B33 * P[3].x;
p.y += B03 * P[0].y + B13 * P[1].y + B23 * P[2].y + B33 * P[3].y;
//pDC->LineTo(ROUND(p.x), ROUND(p.y));
}
参考 《计算几何算法与实现》孔令德