Yes, De Casteljau 算法是要走的路。
参数化
如果您的曲线没有从 t=0 到 t=1 正确参数化,那么您似乎使用了错误的方程来描述您的曲线。维基百科有适合您的正确公式:
B(t) = (1−t)3 P1 + 3(1−t)2t P2 + 3(1−t)t2 P3 + t3 P4
[我将维基百科中的索引从零开始的形式调整为您问题中从一开始的形式。]
If you set t=0, you get P1, your starting point. If you set t=1, you get P4, your endpoint. In between, the shape of the curve is determined by those points and the two control points P2 and P3.
De Casteljau 算法
Let t be the parameter where you want to cut your curve. Let's say you want to keep only the initial part. You draw the three lines from P1 to P2, from there to P3 and from there to P4. Each of these lines you divide at a the fraction t of its length, i.e. the length of the line before the dividing point relates to the entire length as t : 1. You now have three new points P12 through P34. Do the same again to obtain two points P123 and P234, and again to obtain the single point P1234. This final point is B(t), the endpoint of your truncated curve. The startpoint is P1 as before. The new control points are P12 and P123 the way we just constructed them.
删除曲线的初始部分的方法相同。因此,只需两步,您就可以修剪曲线的两端。您将获得一组新的控制点,这些控制点精确地(根据您使用的数字精度)描述原始曲线的一段,不涉及近似值或类似的情况。
您可以将上述所有几何描述转化为代数公式,在完美的世界中,您应该得出以下结果这个答案对于你引用的问题。
唉,这似乎并不是一个完美的世界。在撰写本文时,这些公式仅使用二次多项式,因此无法描述三次曲线上的端点。正确的公式应该如下:
-
P'1 =
u0u0u0 P1 +
(t0u0u0 +
u0t0u0 +
u0u0t0) P2 +
(t0t0u0 +
u0t0t0 +
t0u0t0) P3 +
t0t0t0 P4
-
P'2 =
u0u0u1 P1 +
(t0u0u1 +
u0t0u1 +
u0u0t1) P2 +
(t0t0u1 +
u0t0t1 +
t0u0t1) P3 +
t0t0t1 P4
-
P'3 =
u0u1u1 P1 +
(t0u1u1 +
u0t1u1 +
u0u1t1) P2 +
(t0t1u1 +
u0t1t1 +
t0u1t1) P3 +
t0t1t1 P4
-
P'4 =
u1u1u1 P1 +
(t1u1u1 +
u1t1u1 +
u1u1t1) P2 +
(t1t1u1 +
u1t1t1 +
t1u1t1) P3 +
t1t1t1 P4
where u0 = 1 − t0 and u1 = 1 − t1.
请注意,在括号内的表达式中,至少某些项是相等的并且可以组合。我没有这样做,因为我相信这里所说的公式将使模式更加清晰。您可以简单地独立执行这些计算x and y计算新控制点的指示。