立方贝塞尔曲线段 [英] Cubic bezier curve segment

查看:197
本文介绍了立方贝塞尔曲线段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有描述贝塞尔曲线P1,P2,P3,P4的4个点(其中P1和P4是曲线的终点,P2和P3是曲线的控制点),我怎么能找到只描述这段贝塞尔曲线的点?



我发现这个答案这正是我正在寻找,但答案似乎是错误的。如果我在应该代表整个贝塞尔曲线的方程中设置t0 = 0和t1 = 1,那么得到的点是无效的。它们不等于原始点。



似乎解决方案与De Casteljau算法有关,但我无法理解它是如何工作的。

解决方案

是, De Casteljau的算法就是要走的路。

参数化



如果你的曲线从t = 0到t = t = 1没有正确的参数化,那么看起来你正在用错误的方程描述你的曲线。 维基百科对您具有正确的公式:其中,B(b) (1-t)2 (1-t)t 2 P P(t)= P 2 + i> 3 3 3 4 4



[我将维基百科中基于零的表格的索引从您的问题调整为基于一维表格。]

如果你设置 = 0,你的起点就是

1 。如果你设定 = 1,你的终点就是

4 。在这之间,曲线的形状由这些点和两个控制点P 2和P 3 确定。 >。

De Casteljau算法



让参数在你想要的位置削减你的曲线。假设你只想保留最初的部分。你从这里到P 画出从P 1

2 的三条线> 3 并从那里到

4 。这些线条中的每条线段都是以其长度的分数来分割的,即分割点之前的线条长度与整个长度有关,如下所示:1.您现在有三个新的点

到P

。再次做相同的操作以获得两点

123

234 ,并再次获得单点< I> P 的<子> 1234 。最后一点是B(t),即截断曲线的终点。起始点像前面一样是P 1 。新的控制点是我们刚刚构建它们的方式

b
$ b

移除曲线的初始部分的方式相同。所以在两个步骤中,您可以修剪曲线的两端。您可以获得一组新的控制点,这些控制点恰好(以您使用的数字精度计算)描述的是您的原始曲线的一部分,不包含任何近似值或类似参数。

您可以将上面所有的几何描述转换为代数公式,并且在完美的世界中,您应该拿出这个答案你引用的问题。



唉,这看起来并不是一个完美的世界。在撰写本文时,这些公式仅使用二次多项式,因此它们无法在三次曲线上描述端点。正确的公式应该如下:


  • P' 1 =
    u 0 u 0 u u P 1 +
    0 0 0)
    0 +
    0 0 0 +
    0 0 u (0 0 0 0 2 +
    t 0 0 0 +
    0 0 +
    0 u <0> 0 <0> <0> / sub> 3 3 +
    t 0
    0
    0 4 4

  • P'<2> =
    0 u <0> 0 (1)在下面的例子中,我们可以看到, 0 u u u 1 1 +
    / i> 0 0 u 1 +
    u 0 0 ui 0 t 1 1 0 0 1 >) 2 +
    (t 0 t > 0 1 > 0 0 1 1 3 3 +
    > P
    4

  • 3 =
    u u u u 1 u u / i> 1 +
    0 1 如下所示:1 1 其中 sub> 1 +
    0 0 1 <=> 1 <=> <2> <2> =
    (t <1> i> 0 1 1 1 1 +
    < u <1>
    + P 3,B 3,B 3,B 4,B 4, i> 0 1 1 1 1 1 4


  • 4 =
    1 1 1 1 1 1 1 1 /
    (t)= 1 u
    1< sub> +
    < u> 1< t> 1< u> 1 +
    1 1 1 1 (1)其中,P(t)= t 1(t)= t 1
    1 1 +
    sub> 1 1 1 1 +
    t
    1< 1>< 1> 1< 1> 1< P< i > 3 +
    t 1 1 t >其中 0
    = 1 - 0 1 = 1 - 1 。

    请注意,在括号表达式中,至少有一些这些条款是相同的,可以是c ombined。我相信,我没有这样做,因为这里所述的公式会使模式更清晰。您可以简单地针对 x y 方向独立执行这些计算来计算新的控制点。


    If I have the 4 points describing a Bezier curve P1, P2, P3, P4 (where P1 and P4 are the end points of the curve and P2 and P3 are the control points of the curve), how could I find the points that describes only a segment of this bezier curve?

    I found this answer which is exactly what I am looking for but the answer seems wrong. If I set t0=0 and t1=1 in the equations which should represent the entire bezier curve, the resulting points are not valid. They are not equal to the original points.

    It seems that the solution is related to the De Casteljau's algorithm, but I can't understand how it works.

    解决方案

    Yes, De Casteljau's algorithm is the way to go.

    Parametrization

    If your curve isn't correctly parametrized from t=0 trough t=1, then it seems you're using the wrong equation to descibe your curve. Wikipedia has the correct formula for you:

    B(t) = (1−t)3 P1 + 3(1−t)2t P2 + 3(1−t)t2 P3 + t3 P4

    [I adjusted the indices from the zero-based form in Wikipedia to the one-based from your question.]

    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's algorithm

    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.

    Removing an initial part of the curve works the same way. So in two steps, you can trim both ends of your curve. You obtain a new set of control points which exactly (up to the numeric precision you use) describe a segment of your original curve, with no approximation or similar involved.

    You can translate all of the geometric descriptions above into algebraic formulas, and in a perfect world you should come up with the results from this answer to the question you quoted.

    Alas, this doesn't appear to be a perfect world. At the time of this writing, those formulas only used polynoms of degree two, so they could not describe endpoints on a third degree curve. The correct formula should be the following:

    • 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.

    Note that in the parenthesized expressions, at least some of the terms are equal and can be combined. I did not do so as the formula as stated here will make the pattern clearer, I believe. You can simply execute those computations independently for the x and y directions to compute your new control points.

    这篇关于立方贝塞尔曲线段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆